<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * 异步访问控制器
 */
class Ajax extends MY_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('bbs_detail_model');
        $this->load->model('bbs_account_model');
        $this->load->model('video_model');
    }

    /**
     * 发送注册手机验证码
     */
    function send_reg_code() {
        if ($_POST) {
            $mobile = isset($_POST['uMobile']) ? trim($_POST['uMobile']) : "";
            $flag = preg_match("/^(((13[0-9]{1})|(14[0-9]{1})|(15[0-3,5-9]{1})|(17[0,1,3,5-8]{1})|(18[0-9]{1}))+\d{8})$/", $mobile);
            if (!$flag) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "手机格式不正确";
                echo JSON($mess);
                exit;
            }
            if ($this->users_model->get_user_flag(array("mobile" => $mobile, "is_line" => 0))) {
                $mess['errorMsg'] = '手机号已注册';
                $mess['reqStatus'] = false;
                echo JSON($mess);
                exit;
            }

            $postData = array();
            $postData['mobile'] = $mobile;
            $postData['tpl'] = 'mmp'; //找回密码模板
            $postData['from_type'] = 2;
            $result = $this->crypt->POST_Api($this->remote_url['sms_url'], $postData);
            $result = json_decode($result, true);
            if ($result['result'] == 1) {
                $this->session->set_userdata("register_code", $result['code']);
                $this->session->set_userdata("register_mobile", $mobile);
                $mess['reqStatus'] = true;
                echo JSON($mess);
                exit;
            } else {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作过于频繁";
                echo JSON($mess);
                exit;
            }
        }
    }

    /**
     * 发送找回密码验证码
     */
    function send_findpwd_code() {
        if ($_POST) {
            $mobile = isset($_POST['uMobile']) ? trim($_POST['uMobile']) : "";
            $flag = preg_match("/^(((13[0-9]{1})|(14[0-9]{1})|(15[0-3,5-9]{1})|(17[0,1,3,5-8]{1})|(18[0-9]{1}))+\d{8})$/", $mobile);
            if (!$flag) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "手机格式不正确";
                echo JSON($mess);
                exit;
            }
            if (!$this->users_model->get_user_flag(array('mobile' => $mobile, "is_line" => 0))) {
                $mess['errorMsg'] = '手机号不存在';
                $mess['reqStatus'] = false;
                echo JSON($mess);
                exit;
            }

            $postData = array();
            $postData['mobile'] = $mobile;
            $postData['tpl'] = 'mpp'; //找回密码模板
            $postData['from_type'] = 2;
            $result = $this->crypt->POST_Api($this->remote_url['sms_url'], $postData);
            $result = json_decode($result, true);
            if ($result['result'] == 1) {
                $this->session->set_userdata("findpwd_code", $result['code']);
                $this->session->set_userdata("findpwd_mobile", $mobile);
                $mess['reqStatus'] = true;
                echo JSON($mess);
                exit;
            } else {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作过于频繁";
                echo JSON($mess);
                exit;
            }
        }
    }

    /**
     * 发送绑定手机验证码
     */
    function send_bmobile_code() {
        if ($_POST) {
            $mobile = isset($_POST['uMobile']) ? trim($_POST['uMobile']) : "";
            $flag = preg_match("/^(((13[0-9]{1})|(14[0-9]{1})|(15[0-3,5-9]{1})|(17[0,1,3,5-8]{1})|(18[0-9]{1}))+\d{8})$/", $mobile);
            if (!$flag) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "手机格式不正确";
                echo JSON($mess);
                exit;
            }

            $postData = array();
            $postData['mobile'] = $mobile;
            $postData['tpl'] = 'mmp'; //找回密码模板
            $postData['from_type'] = 2;
            $result = $this->crypt->POST_Api($this->remote_url['sms_url'], $postData);
            $result = json_decode($result, true);
            if ($result['result'] == 1) {
                $this->session->set_userdata("thirdlogin_code", $result['code']); //
                $this->session->set_userdata("thirdlogin_mobile", $mobile);
                $mess['reqStatus'] = true;
                echo JSON($mess);
                exit;
            } else {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作过于频繁";
                echo JSON($mess);
                exit;
            }
        }
    }

    /**
     * 发送绑定新手机验证码
     */
    function send_bindmoble_code() {
        if ($_POST) {
            $mobile = isset($_POST['uMobile']) ? trim($_POST['uMobile']) : "";
            $flag = preg_match("/^(((13[0-9]{1})|(14[0-9]{1})|(15[0-3,5-9]{1})|(17[0,1,3,5-8]{1})|(18[0-9]{1}))+\d{8})$/", $mobile);
            if (!$flag) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "手机格式不正确";
                echo JSON($mess);
                exit;
            }
            if ($this->users_model->get_user_flag(array("mobile" => $mobile, "is_line" => 0))) {
                $mess['errorMsg'] = '手机号已被注册';
                $mess['reqStatus'] = false;
                echo JSON($mess);
                exit;
            }
            $postData = array();
            $postData['mobile'] = $mobile;
            $postData['tpl'] = 'mmp'; //找回密码模板
            $postData['from_type'] = 2;
            $result = $this->crypt->POST_Api($this->remote_url['sms_url'], $postData);
            $result = json_decode($result, true);
            if ($result['result'] == 1) {
                $this->session->set_userdata("bindmobile_code", $result['code']); //
                $this->session->set_userdata("bindmobile_mobile", $mobile);
                $mess['reqStatus'] = true;
                echo JSON($mess);
                exit;
            } else {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作过于频繁";
                echo JSON($mess);
                exit;
            }
        }
    }

    /**
     * 发送修改交易密码手机验证码
     */
    function send_paypass_code() {
        $this->is_login();
        if ($_POST) {
            $mobile = $this->db->query("select mobile from tan_users where user_id = " . $this->user_id . " order by user_id limit 1")->row_array();
            if (!$mobile['mobile']) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "你还未绑定手机号哦";
                echo JSON($mess);
                exit;
            }

            $postData = array();
            $postData['mobile'] = $mobile['mobile'];
            $postData['tpl'] = 'mmp'; //找回密码模板
            $postData['from_type'] = 2;
            $result = $this->crypt->POST_Api($this->remote_url['sms_url'], $postData);
            $result = json_decode($result, true);
            if ($result['result'] == 1) {
                $this->session->set_userdata("paypass_code", $result['code']);
                $mess['reqStatus'] = true;
                echo JSON($mess);
                exit;
            } else {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作过于频繁";
                echo JSON($mess);
                exit;
            }
        }
    }
    /**
     * 发送提现绑定手机验证码
     */
    function send_bind_code() {
        $this->is_login();
        if ($_POST) {
            $mobile = $this->db->query("select mobile from tan_users where user_id = " . $this->user_id . " order by user_id limit 1")->row_array();
            if (!$mobile['mobile']) {
                $mess['errorNo'] = 1;
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "你还未绑定手机号哦，立即绑定";
                echo JSON($mess);
                exit;
            }

            $postData = array();
            $postData['mobile'] = $mobile['mobile'];
            $postData['tpl'] = 'mmp'; //找回密码模板
            $postData['from_type'] = 1;
            $result = $this->crypt->POST_Api($this->remote_url['sms_url'], $postData);
            $result = json_decode($result, true);
            if ($result['result'] == 1) {
                $this->session->set_userdata("paypass_code", $result['code']);
                $mess['reqStatus'] = true;
                echo JSON($mess);
                exit;
            } else {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作过于频繁";
                echo JSON($mess);
                exit;
            }
        }
    }
    /**
     * 发送修改手机验证码
     */
    function send_checkmobile_code() {
        $this->is_login();
        if ($_POST) {
            $mobile = $this->db->query("select mobile from tan_users where user_id = " . $this->user_id . " order by user_id limit 1")->row_array();
            if (!$mobile['mobile']) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "你还未绑定手机号哦";
                echo JSON($mess);
                exit;
            }

            $postData = array();
            $postData['mobile'] = $mobile['mobile'];
            $postData['tpl'] = 'mmp'; //找回密码模板
            $postData['from_type'] = 2;
            $result = $this->crypt->POST_Api($this->remote_url['sms_url'], $postData);
            $result = json_decode($result, true);
            if ($result['result'] == 1) {
                $this->session->set_userdata("checkmobile_code", $result['code']); //
                $this->session->set_userdata("checkmobile_mobile", $mobile['mobile']);
                $mess['reqStatus'] = true;
                echo JSON($mess);
                exit;
            } else {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作过于频繁";
                echo JSON($mess);
                exit;
            }
        }
    }

    //个人文章收藏
    function get_arts_collect_json() {
        $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
        $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
        $uuid = decrypt_user_id($uuid);
        $where = array();
        $where['f.user_id'] = $uuid;
        $where['f.is_del'] = 1;
        $records_per_page = 10;
        $dataOffset = 10 + $pageIndex * $records_per_page;
        $list = $this->db->query("select f.id,f.article_id,f.is_del,a.title,a.thumb,a.readnum,a.commentnum,a.create_time from tan_bbs_favorite f left join tan_bbs_article a on a.id = f.article_id where f.user_id = " . $uuid . " and f.is_del = 1 order by f.id desc limit $dataOffset,$records_per_page")->result_array();
        $html = "";
        foreach ($list as $key => $val) {
            $user_id = encrypt_user_id($val['author_id']);
            $val['detail_url'] = site_url("p/" . encrypt_article_id($val['article_id']));
            $val['create_time'] = date("m-d H:i", $val['create_time']);
            $html .= "<section>
                        <a href='$val[detail_url]' class='article-box f-cb'>
                            <div class='pic fl'>
                                <img src='$val[thumb]'/>
                            </div>
                            <div class='article-detail'>
                                <p class='title'>$val[title]</p>
                                <p class='state f-cb'>
                                    <span class='fl'>$val[create_time]</span>
                                    <span class='fr'>$val[commentnum]</span><font class='iconfont fr'>&#xe675;</font>
                                    <span class='fr mr8'>$val[readnum]</span><font class='iconfont fr mr3'>&#xe60a;</font>
                                </p>
                            </div>
                        </a>
                    </section>";
        }
        echo $html;
        die;
    }

    //获取自己的关注
    function get_self_follows() {
        $this->is_login();
        $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
        $records_per_page = 10;
        $dataOffset = 10 + $pageIndex * $records_per_page;
        $list = $this->db->query("select f.*,i.nickname,i.head_img,i.signature from tan_bbs_fans f left join tan_users_info i on i.user_id = f.user_id where f.followuid = " . $this->user_id . " and f.is_del = 1 order by f.id desc limit $dataOffset,$records_per_page")->result_array();
        $html = "";
        foreach ($list as $key => $val) {
            $user_id = encrypt_user_id($val['user_id']);
            $val['head_img'] = strstr($val['head_img'], "http") ? $val['head_img'] : $this->img_host . $val['head_img'];
            $html .= "<li data-uid='$user_id'>
                        <div class='w100'>
                                <div class='f_left'>
                                        <a href='" . site_url("u/" . $user_id) . "'><img src='$val[head_img]' alt='$val[nickname]'></a>		
                                </div>
                                <div class='hers-con clearfix'>
                                        <a class='fl' href='" . site_url("u/" . $user_id) . "'>
                                                <em class='nickname'>$val[nickname]</em>
                                                <img src='/static/weixin/img/vip/vip1.png' alt='' /><br>
                                                <span class='ourselves'>$val[signature]</span>
                                        </a>
                                        <button class='iconfont _follow icon-followed' data-val='1'>&#xe691;</button>
                                </div>
                        </div>
                    </li>";
        }
        echo $html;
        die;
    }

    //获取自己的粉丝
    function get_self_fans() {
        $this->is_login();
        $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
        $records_per_page = 10;
        $dataOffset = 10 + $pageIndex * $records_per_page;
        $list = $this->db->query("select f.*,i.nickname,i.head_img,i.signature from tan_bbs_fans f left join tan_users_info i on i.user_id = f.followuid where f.user_id = " . $this->user_id . " and f.is_del = 1 order by f.id desc limit $dataOffset,$records_per_page")->result_array();
        $html = "";
        foreach ($list as $key => $val) {
            $user_id = encrypt_user_id($val['followuid']);
            //验证是否互相关注
            $is_fan = $this->bbs_user_model->get_fan_status(array("user_id" => $val['followuid'], "followuid" => $this->user_id, "is_del" => 1));
            $is_fan = $is_fan ? 1 : 0;
            $val['head_img'] = strstr($val['head_img'], "http") ? $val['head_img'] : $this->img_host . $val['head_img'];
            $html .= "<li data-uid='$user_id'>
                        <div class='w100'>
                                <div class='f_left'>
                                        <a href='" . site_url("u/" . $user_id) . "'><img src='$val[head_img]' alt='$val[nickname]'></a>		
                                </div>
                                <div class='hers-con clearfix'>
                                        <a class='fl' href='" . site_url("u/" . $user_id) . "'>
                                                <em class='nickname'>$val[nickname]</em>
                                                <img src='/static/default/img/vip/vip1.png' alt='' /><br>
                                                <span class='ourselves'>$val[signature]</span>
                                        </a>
                                        <button class='iconfont _follow " . ($is_fan ? "icon-followed" : "icon-unfollow") . "' data-val='$is_fan'>" . ($is_fan ? "&#xe691;" : "&#xe6b6;") . "</button>
                                </div>
                        </div>
                    </li>";
        }
        echo $html;
        die;
    }

    //获取溜溜币明细
    function get_finance_json() {
        $this->is_login();
        if ($_POST) {
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $type = isset($_REQUEST['type']) ? trim($_REQUEST['type']) : "income";
            $records_per_page = 15;
            $dataOffset = $pageIndex * $records_per_page;
            if ($type == "income") {
                $dot = "+";
                $where = "f.type = 1 and f.user_id = " . $this->user_id;
            } else {
                $dot = "-";
                $where = "f.type = 2 and f.user_id = " . $this->user_id;
            }

            $list = $this->db->query("select * from tan_finance_list f where $where order by id desc limit $dataOffset,$records_per_page")->result_array();
            $html = "";
            foreach ($list as $key => $val) {
                $html .= "<tr>";
                $html .= "    <td>" . date("y/m/d", $val['create_time']) . "<span></b></td>";
                $html .= "    <td>" . $this->finance_award_type($val['reward_type']) . "</td>";
                $html .= "    <td>$dot<i>" . number_format($val['finance']) . "</i>溜溜币</td>";
                $html .= "</tr>";
            }
            echo $html;
            die;
        }
    }

    //获取提现记录
    function get_withdraw_json() {
        $this->is_login();
        if ($_POST) {
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $records_per_page = 10;
            $dataOffset = $pageIndex * $records_per_page;

            $list = $this->db->query("select * from tan_withdraw_order where user_id = " . $this->user_id . " and without_type = 1 order by id desc limit $dataOffset,$records_per_page")->result_array();
            $html = "";
            foreach ($list as $key => $val) {
                $finance = floatval($val['amount']);
                if ($val['status'] == 1) {
                    $html .= "<li>";
                    $html .= "    <p>收款帐号：<em>$val[account]</em></p>";
                    $html .= "    <div class='detail f-cb'>";
                    $html .= "        <div class='statue payed fl'>";
                    $html .= "            <font class='iconfont'>&#xe62d;</font>已支付";
                    $html .= "        </div>";
                    $html .= "        <p class='fl'><span class='fl'>提现<i class='col-red'>$val[amount]</i>元</span><br/><span class='fl collectier'>收款人:$val[name]</span></p>";
                    $html .= "        <p class='fr'><span class='fr'>" . $finance . "万溜溜币</span><br/><span class='fr'>" . date('Y-m-d', $val['create_time']) . "</span></p>";
                    $html .= "    </div>";
                    $html .= "</li>";
                } else {
                    $html .= "<li>";
                    $html .= "    <p>收款帐号：<em>$val[account]</em></p>";
                    $html .= "    <div class='detail f-cb'>";
                    $html .= "        <div class='statue fl'>";
                    $html .= "            <font class='iconfont'>&#xe64b;</font>审核中";
                    $html .= "        </div>";
                    $html .= "        <p class='fl'><span class='fl'><i class='col-red'>$val[amount]</i></span><br/><span class='fl collectier'>收款人:$val[name]</span></p>";
                    $html .= "        <p class='fr'><span class='fr'>" . $finance . "万溜溜币</span><br/><span class='fr'>" . date('Y-m-d', $val['create_time']) . "</span></p>";
                    $html .= "    </div>";
                    $html .= "</li>";
                }
            }
            echo $html;
            die;
        }
    }

    //文章首页下拉加载更多文章
    function ajax_more_fetch_arts() {
        if ($_POST) {
            $currentPage = isset($_POST['currentPage']) ? trim($_POST['currentPage']) : 0;
            $perDataCount = 14;
            $limitIndex = 27 + $currentPage * $perDataCount;
            $query_params = "a.id,a.authorid,a.title,a.thumb,a.content,a.readnum,a.commentnum,a.create_time,u.head_img,u.nickname";
            $list = $this->db->query("select $query_params from tan_bbs_article a left join tan_users_info u on u.user_id = a.authorid where a.status = 1 and a.hot = 1 order by a.hot desc,a.sort desc limit $limitIndex,$perDataCount")->result_array();
            $html = "";
            foreach ($list as $key => $val) {
                $matches = array();
                preg_match_all("/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png|\.bmp|\.jpeg]))[\'|\"].*?[\/]?>/i", $val['content'], $matches);
                $content_thumb = $matches[1][0] ? $matches[1][0] : "";
                $val['content_thumb'] = $content_thumb;
                $val['detail_url'] = site_url("p/" . encrypt_article_id($val['id']));
                $val['space_url'] = site_url("u/" . encrypt_user_id($val['authorid']));
                $val['article_id'] = encrypt_article_id($val['id']);
                $val['head_img'] = strstr($val['head_img'], "http") ? $val['head_img'] : $this->img_host . $val['head_img'];
                if ($key % 7 == 0) {
                    $val['title'] = mb_strcut($val['title'], 0, 55, "utf8") . "...";
                    $html .= "<section class='nth4' id='list-$val[article_id]' data-id='$val[article_id]'>
                                <a href='$val[detail_url]' class='article-box'><img src='$val[content_thumb]' alt='$val[title]'></a>
                                <p class='state4-title textnum15'>$val[title]</p>
                                <!--<p class='state state4 f-cb'>
                                    <font class='iconfont fl ml15'></font><span class='fl mr8'>$val[commentnum]</span><font class='iconfont fl mr3 ml15'></font><span class='fl'>$val[readnum]</span>
                                    <i class='fr mr15'>
                                        <img src='$val[head_img]' alt='$val[nickname]'>
                                        <span>$val[nickname]</span>
                                    </i>-->
                                </p>
                            </section>";
                } else {
                    $html .= "<section  id='list-$val[article_id]' data-id='$val[article_id]'>
                                    <a href='$val[detail_url]' class='article-box f-cb'>
                                        <div class='pic fl'>
                                            <img class='lazy' data-original='$val[thumb]' alt='$val[title]'>
                                        </div>
                                        <div class='article-detail'>
                                            <p class='title'>$val[title]</p>
                                            <p class='state f-cb'>
                                                <font class='iconfont fl'>&#xe675;</font><span class='fl mr8'>$val[commentnum]</span><font class='iconfont fl mr3'>&#xe60a;</font><span class='fl'>$val[readnum]</span>
                                                <i class='fr'>
                                                    <img src='$val[head_img]' class='mr3' alt='$val[nickname]'>
                                                    <span>$val[nickname]</span>
                                                </i>
                                            </p>
                                        </div>
                                    </a>
                                </section>";
                }
            }
            $result = array(
                "currentPage" => $list ? $currentPage + 1 : $currentPage,
                "htmlData" => $html,
            );
            echo $html;
            die;
        }
    }

    //获取更多借款平台
    function ajax_more_fetch_loan() {
        if ($_POST) {
            $currentPage = isset($_POST['currentPage']) ? trim($_POST['currentPage']) : 0;
            $perDataCount = 12;
            $limitIndex = 12 + $currentPage * $perDataCount;
            $list = $this->db->query("select l.id,l.name_ch,l.logo_list,l.amount_area,l.rate,l.tip_list,l.is_recommand from tan_lend_list l where l.status = 1 order by l.is_recommand desc,l.sort desc,l.id desc limit $limitIndex,$perDataCount")->result_array();
            $html = "";
            foreach ($list as $key => $val) {
                $rate = ($val['rate'] * 100);
                $rate_str = $rate * 1000 % 10 == 0 ? number_format($rate, 2) . '%' : number_format($rate, 3) . '%';
                $html .= "<li>";
                $html .= "    <a class='f-cb' href='" . site_url("loan/" . $val['id']) . "'>";
                $html .= "       <div class='plat f-cb'>";
                $html .= "           <div class='fl img-box'>";
                $html .= "               <i><em><img src='" . $val['logo_list'] . "'/></em></i>";
                $html .= "           </div>";
                $html .= "           <div class='fl abr'>";
                $html .= "               <i><em>";
                $html .= "               <p>" . $val['name_ch'] . "</p>";
                $html .= "               <p>可贷额度：" . $val['amount_area'] . "元</p>";
                $html .= "               <p>参考日利率：" . $rate_str . "/天</p>";
                $html .= "               </em></i>";
                $html .= "           </div>";
                $html .= "           <div class='fr iconfont'><i><em>&#xe662;</em></i></div>";
                $html .= "       </div>";
                $html .= "       <p class='p-detail fr'>" . $val['tip_list'] . "</p>";
                $html .= "    </a>";
                $html .= " </li>";
            }
            echo $html;
            die;
        }
    }

    //获取更多借款平台2
    function ajax_more_fetch_loan_json() {
        if ($_POST) {
            $currentPage = isset($_POST['currentPage']) ? trim($_POST['currentPage']) : 0;
            $perDataCount = 10;
            $limitIndex = 10 + $currentPage * $perDataCount;
            $list = $this->db->query("select id,logo_list,name_ch,amount_area_alisa,rate,tip_list,is_recommand from tan_lend_list where status = 1 order by is_recommand desc,sort desc,id desc limit $limitIndex,$perDataCount")->result_array();
            $html = "";
            foreach ($list as $key => $val) {
                $rate = ($val['rate'] * 100);
                $rate_str = $rate * 1000 % 10 == 0 ? number_format($rate, 2) . '%' : number_format($rate, 3) . '%';
                $html .= "<li>";
                $html .= "    <a class='f-cb' href='" . site_url("loan/" . $val['id']) . "'>";
                $html .= "       <div class='fl'>";
                $html .= "           <img src='" . $val['logo_list'] . "'/>";
                $html .= "           <div class='may_loan'>";
                $html .= "               <em>$val[amount_area_alisa]</em>";
                $html .= "               <p>可贷额度</p>";
                $html .= "           </div>";
                $html .= "       </div>";
                $html .= "       <div class='fr f-cb'>";
                $html .= "       <div class='img-box'>";
                if ($val['is_recommand']) {
                    $html .= "           <img src='/static/weixin/img/finance/new_recommend.png'/>";
                }
                $html .= "       </div>";
                $html .= "           <div class='may_loan'>";
                $html .= "               <em>$rate_str/天</em>";
                $html .= "               <p>参考日利率</p>";
                $html .= "           </div>";
                $html .= "       </div>";
                $html .= "    </a>";
                $html .= "    <p>" . $val['tip_list'] . "</p>";
                $html .= " </li>";
            }
            echo $html;
            die;
        }
    }

    //获取更多借款平台
    function ajax_search_more_loan_json() {
        if ($_POST) {
            $kw = trim($_POST['keyWord']);
            $currentPage = isset($_POST['pageIndex']) ? trim($_POST['pageIndex']) : 0;
            $perDataCount = 12;
            $limitIndex = 12 + $currentPage * $perDataCount;
            $list = $this->db->query("select l.id,l.name_ch,l.logo_list,l.amount_area,l.rate,l.tip_list,l.is_recommand from tan_lend_list l where l.status = 1 and l.name_ch like '%$kw%' order by l.is_recommand desc,l.sort desc,l.id desc limit $limitIndex,$perDataCount")->result_array();
            $html = "";
            foreach ($list as $key => $val) {
                $rate = ($val['rate'] * 100);
                $rate_str = $rate * 1000 % 10 == 0 ? number_format($rate, 2) . '%' : number_format($rate, 3) . '%';
                $html .= "<li>";
                $html .= "    <a class='f-cb' href='" . site_url("loan/" . $val['id']) . "'>";
                $html .= "       <div class='plat f-cb'>";
                $html .= "           <div class='fl img-box'>";
                $html .= "               <i><em><img src='" . $val['logo_list'] . "'/></em></i>";
                $html .= "           </div>";
                $html .= "           <div class='fl abr'>";
                $html .= "               <i><em>";
                $html .= "               <p>" . $val['name_ch'] . "</p>";
                $html .= "               <p>可贷额度：" . $val['amount_area'] . "元</p>";
                $html .= "               <p>参考日利率：" . $rate_str . "/天</p>";
                $html .= "               </em></i>";
                $html .= "           </div>";
                $html .= "           <div class='fr iconfont'><i><em>&#xe662;</em></i></div>";
                $html .= "       </div>";
                $html .= "       <p class='p-detail fr'>" . $val['tip_list'] . "</p>";
                $html .= "    </a>";
                $html .= " </li>";
            }
            echo $html;
            die;
        }
    }

    //获取更多借款平台 新
    function ajax_search_more_loan_json_new() {
        if ($_POST) {
            $kw = trim($_REQUEST['keyWord']);

            $like = '';
            if ($kw) {
                $like .= " and name_ch like '%$kw%'";
            }

            //增加检索
            $amount_id = trim($_REQUEST['amount_id']);
            if ($amount_id) {
                switch ($amount_id){
                    case 4:
                        $like .= " and amount_first <= 2000 ";
                        break;
                    case 12:
                        $like .= " and (amount_first <= 5000 and amount_over>=2000)";
                        break;
                    case 13:
                        $like .= " and (amount_first <= 10000 and amount_over>=5000)";
                        break;
                    case 14:
                        $like .= " and (amount_first <= 20000 and amount_over>=10000)";
                        break;
                    case 15:
                        $like .= " and (amount_first <= 50000 and amount_over>=20000)";
                        break;
                    case 16:
                        $like .= " and (amount_over >= 50000)";
                        break;
                    default :
                        break;
                }
            }
            $period_id = trim($_REQUEST['period_id']);
            if ($period_id) {
                $like .= " and period_id in(" . $period_id . ")";
            }
            $lend_id = trim($_REQUEST['lend_id']);
            if ($lend_id) {
                $like .= " and lend_id like '%" . $lend_id . "%'";
            }
            //增加排序
            $orderby = trim($_REQUEST['orderby']);
            switch ($orderby) {
                case "amount":
                    $orderby = "l.is_recommand desc,l.amount_over desc,l.sort desc,l.id desc";
                    break;
                case "rate":
                    $orderby = "l.is_recommand desc,l.rate_id asc,l.sort desc,l.id desc";
                    break;
                case "tip":
                    $orderby = "l.is_recommand desc,l.tip_lending_desc asc,l.sort desc,l.id desc";
                    break;
                default :
                    $orderby = "l.is_recommand desc,l.sort desc,l.id desc,l.sort desc,l.id desc";
            }

            $currentPage = isset($_POST['pageIndex']) ? trim($_POST['pageIndex']) : 0;
            $perDataCount = 12;
            $limitIndex = $currentPage * $perDataCount;
//            echo "select l.id,l.name_ch,l.logo_list,logo_small,l.amount_area,l.rate,l.tip_list,l.is_recommand from tan_lend_list l where l.status = 1 $like order by $orderby limit $limitIndex,$perDataCount";
            $list = $this->db->query("select l.id,l.name_ch,l.logo_list,logo_small,l.amount_first,l.amount_over,l.rate,l.tip_list,l.is_recommand from tan_lend_list l where l.status = 1 and is_mobile=1 $like order by $orderby limit $limitIndex,$perDataCount")->result_array();
            $html = "";
            foreach ($list as $key => $val) {
                $rate = ($val['rate'] * 100);
                $rate_str = number_format($rate * 1000) % 10 == 0 ? number_format($rate, 2) . '%' : number_format($rate, 3) . '%';
                $html .= "<li>";
                $html .= "    <a class='f-cb' href='" . site_url("loan/" . $val['id']) . "'>";
                $html .= "           <img src='" . $val['logo_small'] . "' class='fl'/>";
                $html .= "           <div class='fl txt'>";
                if ($val['is_recommand'] == 1) {
                    $html .= "               <h5>" . $val['name_ch'] . "<img src='/static/weixin/img/new.gif' style='display:inline-block;width: 23px;height:  auto;margin-left: 8px;margin-top: -10px;'></h5>";
                } else {
                    $html .= "               <h5>" . $val['name_ch'] . "</h5>";
                }
                $html .= "               <p>" . $val['tip_list'] . "</p>";
                $html .= "               <p>额度：<span>" . $val['amount_first'] . "~" . $val['amount_over'] . "元</span>参考费率：<span>" . $rate_str . "/日</span></p>";
                $html .= "           </div>";
                $html .= "           <div class='go iconfont fr'></div>";
                $html .= "    </a>";
                $html .= " </li>";
            }
            echo $html;
            die;
        }
    }

    //获取更多借款平台 -- 首页 换一换
    function ajax_index_more_loan_json() {
        if ($_POST) {
            $currentPage = isset($_POST['pageIndex']) ? trim($_POST['pageIndex']) : 0;
            $perDataCount = 5;
            $limitIndex = $currentPage * $perDataCount;
            $total = $this->db->query("select count(1) as count from tan_lend_list where status = 1 and is_mobile=1")->result_array();
            //var_dump($total);exit();
            $totalpage = number_format($total[0]['count'] / $perDataCount) + 1;
//            $page = ($currentPage) % $totalpage;
//            $page = $page * $perDataCount;
            //aaa
            $list = $this->db->query("select l.id,l.name_ch,l.logo_small,l.amount_first,l.amount_over,l.rate,l.tip_list,l.is_recommand from tan_lend_list l where l.status = 1 and is_mobile=1  order by l.sort desc,l.id desc limit $limitIndex,$perDataCount")->result_array();
            $html = "";
            foreach ($list as $key => $val) {
                $rate = ($val['rate'] * 100);
                $rate_str = number_format($rate * 1000) % 10 == 0 ? number_format($rate, 2) . '%' : number_format($rate, 3) . '%';
                $html .= "<li>";
                $html .= "    <a class='f-cb' href='/loan/jumpload.html?lend_id=".$val['id']."'>";
                $html .= "           <img src='" . $val['logo_small'] . "' class='fl'/>";
                $html .= "           <div class='fl txt'>";
                if ($val['is_recommand'] == 1) {
                    $html .= "               <h5>" . $val['name_ch'] . "<img src='/static/weixin/img/new.gif' style='display:inline-block;width: 23px;height:  auto;margin-left: 8px;margin-top: -10px;'></h5>";
                } else {
                    $html .= "               <h5>" . $val['name_ch'] . "</h5>";
                }
                $html .= "               <p>" . $val['tip_list'] . "</p>";
                $html .= "               <p>额度：<span>" . $val['amount_first'] . "~" . $val['amount_over'] . "元</span>参考费率：<span>" . $rate_str . "/日</span></p>";
                $html .= "           </div>";
                $html .= "       <div class='go iconfont fr'>&#xe662;</div>";
                $html .= "    </a>";
                $html .= " </li>";
            }
            echo $html;
            die;
        }
    }

    //获取借款平台 金额 时间--
    function ajax_loan_amount_time() {
        if ($_POST) {
            $lend_id = isset($_POST['lend_id']) ? trim($_POST['lend_id']) : 0;
            $query_params = "amount_area,period_area,amount_area_arr,period_area_arr";
            $item = $this->db->query("select $query_params from tan_lend_list where id = $lend_id order by id desc limit 1")->row_array();
            $result['amount_area_arr'] = explode(",", $item['amount_area_arr']);
            $result['period_area_arr'] = explode(",", $item['period_area_arr']);

            echo json_encode($result);
            die;
        } else {
            echo '123';
            die;
        }
    }

    //获取他人的粉丝
    function get_other_fans() {

        $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
        $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
        $uuid = decrypt_user_id($uuid);
        $records_per_page = 10;
        $dataOffset = 10 + $pageIndex * $records_per_page;
        $list = $this->db->query("select f.*,i.nickname,i.head_img,i.signature from tan_bbs_fans f left join tan_users_info i on i.user_id = f.followuid where f.user_id = " . $uuid . " and f.is_del = 1 order by f.id desc limit $dataOffset,$records_per_page")->result_array();
        $html = "";
        foreach ($list as $key => $val) {
            $user_id = encrypt_user_id($val['followuid']);
            $val['head_img'] = strstr($val['head_img'], "http") ? $val['head_img'] : $this->img_host . $val['head_img'];
            //验证是否互相关注
            $is_fan = $this->user_id ? $this->bbs_user_model->get_fan_status(array("user_id" => $val['user_id'], "followuid" => $this->user_id, "is_del" => 1)) : 0;
            $is_fan = $is_fan ? 1 : 0;
            $html .= "<li data-uid='$user_id'>
                        <div class='w100'>
                                <div class='f_left'>
                                        <a href='" . site_url("u/" . $user_id) . "'><img src='$val[head_img]' alt='$val[nickname]'></a>		
                                </div>
                                <div class='hers-con clearfix'>
                                        <a class='fl' href='" . site_url("u/" . $user_id) . "'>
                                                <em class='nickname'>$val[nickname]</em>
                                                <img src='/static/default/img/vip/vip1.png' alt='' /><br>
                                                <span class='ourselves'>$val[signature]</span>
                                        </a>
                                        <button class='iconfont _follow " . ($is_fan ? "icon-followed" : "icon-unfollow") . "' data-val='$is_fan'>" . ($is_fan ? "&#xe691;" : "&#xe6b6;") . "</button>
                                </div>
                        </div>
                    </li>";
        }
        echo $html;
        die;
    }

    //获取他人的关注
    function get_other_follows() {
        $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
        $uuid = decrypt_user_id($uuid);
        $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
        $records_per_page = 10;
        $dataOffset = 10 + $pageIndex * $records_per_page;
        $list = $this->db->query("select f.*,i.nickname,i.head_img,i.signature from tan_bbs_fans f left join tan_users_info i on i.user_id = f.user_id where f.followuid = " . $uuid . " and f.is_del = 1 order by f.id desc limit $dataOffset,$records_per_page")->result_array();
        $html = "";
        foreach ($list as $key => $val) {
            $user_id = encrypt_user_id($val['user_id']);
            //验证是否互相关注
            $is_fan = $this->user_id ? $this->bbs_user_model->get_fan_status(array("user_id" => $val['user_id'], "followuid" => $this->user_id, "is_del" => 1)) : 0;
            $is_fan = $is_fan ? 1 : 0;
            $val['head_img'] = strstr($val['head_img'], "http") ? $val['head_img'] : $this->img_host . $val['head_img'];
            $html .= "<li data-uid='$user_id'>
                        <div class='w100'>
                                <div class='f_left'>
                                        <a href='" . site_url("u/" . $user_id) . "'><img src='$val[head_img]' alt='$val[nickname]'></a>		
                                </div>
                                <div class='hers-con clearfix'>
                                        <a class='fl' href='" . site_url("u/" . $user_id) . "'>
                                                <em class='nickname'>$val[nickname]</em>
                                                <img src='/static/default/img/vip/vip1.png' alt='' /><br>
                                                <span class='ourselves'>$val[signature]</span>
                                        </a>
                                       <button class='iconfont _follow " . ($is_fan ? "icon-followed" : "icon-unfollow") . "' data-val='$is_fan'>" . ($is_fan ? "&#xe691;" : "&#xe6b6;") . "</button>
                                </div>
                        </div>
                    </li>";
        }
        echo $html;
        die;
    }

    //文章搜索页面
    function ajax_search_art_json() {
        if ($_POST) {
            $kw = trim($_POST['keyWord']);
            $query_params = "a.id,a.authorid,a.title,a.thumb,a.content,a.readnum,a.commentnum,a.create_time,u.head_img,u.nickname";
            $list = $this->db->query("select $query_params from tan_bbs_article a left join tan_users_info u on u.user_id = a.authorid where a.title like '%$kw%' and a.status = 1 and a.show = 1 order by a.hot desc,a.sort desc limit 15")->result_array();
            $html = "";
            foreach ($list as $key => $val) {
                $val['detail_url'] = site_url("p/" . encrypt_article_id($val['id']));
                $val['space_url'] = site_url("u/" . encrypt_user_id($val['authorid']));
                $val['article_id'] = encrypt_article_id($val['id']);
                $val['head_img'] = strstr($val['head_img'], "http") ? $val['head_img'] : $this->img_host . $val['head_img'];
                $val['title'] = str_replace($kw, "<span class='col-red'>$kw</span>", $val['title']);
                $html .= "<section  id='list-$val[article_id]' data-id='$val[article_id]'>
                                <a href='$val[detail_url]' class='article-box f-cb'>
                                    <div class='pic fl'>
                                        <img src='$val[thumb]' alt='$val[title]'>
                                    </div>
                                    <div class='article-detail'>
                                        <p class='title'>$val[title]</p>
                                        <p class='state f-cb'>
                                            <font class='iconfont fl'>&#xe675;</font><span class='fl mr8'>$val[commentnum]</span><font class='iconfont fl mr3'>&#xe60a;</font><span class='fl'>$val[readnum]</span>
                                            <i class='fr'>
                                                <img src='$val[head_img]' class='mr3' alt='$val[nickname]'>
                                                <span>$val[nickname]</span>
                                            </i>
                                        </p>
                                    </div>
                                </a>
                            </section>";
            }
            $result = array(
                "reqStatus" => true,
                "htmlData" => $html,
            );
            echo json_encode($result, JSON_HEX_TAG);
            die;
        }
    }

    //文章搜索下拉更多
    function ajax_search_more_art_json() {
        if ($_POST) {
            $kw = trim($_POST['keyWord']);
            $pageIndex = isset($_POST['pageIndex']) ? trim($_POST['pageIndex']) : 0;
            $records_per_page = 15;
            $limitIndex = 15 + $pageIndex * $records_per_page;
            $query_params = "a.id,a.authorid,a.title,a.thumb,a.content,a.readnum,a.commentnum,a.create_time,u.head_img,u.nickname";
            $list = $this->db->query("select $query_params from tan_bbs_article a left join tan_users_info u on u.user_id = a.authorid where a.title like '%$kw%' and a.status = 1 and a.show = 1 order by a.hot desc,a.sort desc limit $limitIndex,$records_per_page")->result_array();
            $html = "";
            foreach ($list as $key => $val) {
                $val['detail_url'] = site_url("p/" . encrypt_article_id($val['id']));
                $val['space_url'] = site_url("u/" . encrypt_user_id($val['authorid']));
                $val['article_id'] = encrypt_article_id($val['id']);
                $val['head_img'] = strstr($val['head_img'], "http") ? $val['head_img'] : $this->img_host . $val['head_img'];
                $val['title'] = str_replace($kw, "<span class='col-red'>$kw</span>", $val['title']);
                $html .= "<section  id='list-$val[article_id]' data-id='$val[article_id]'>
                                <a href='$val[detail_url]' class='article-box f-cb'>
                                    <div class='pic fl'>
                                        <img src='$val[thumb]' alt='$val[title]'>
                                    </div>
                                    <div class='article-detail'>
                                        <p class='title'>$val[title]</p>
                                        <p class='state f-cb'>
                                            <font class='iconfont fl'>&#xe675;</font><span class='fl mr8'>$val[commentnum]</span><font class='iconfont fl mr3'>&#xe60a;</font><span class='fl'>$val[readnum]</span>
                                            <i class='fr'>
                                                <img src='$val[head_img]' class='mr3' alt='$val[nickname]'>
                                                <span>$val[nickname]</span>
                                            </i>
                                        </p>
                                    </div>
                                </a>
                            </section>";
            }
            echo $html;
            die;
        }
    }

    //文章详情页下拉加载更多文章
    function ajax_fetch_art_comment() {
        if ($_POST) {
            $article_id = isset($_REQUEST['article_id']) ? trim($_REQUEST['article_id']) : 0; //文章id
            $currentPage = isset($_REQUEST['currentPage']) ? trim($_REQUEST['currentPage']) : 0; //分页
            $article_id = decrypt_article_id($article_id);
            $records_per_page = 15;
            //获取文章
            $article = $this->db->select("id,authorid,status")->from("bbs_article")->where(array("id" => $article_id))->order_by("create_time desc")->get()->row_array();
            if (!$article) {
                echo "";
                die;
            }
            $where = array();
            $where['c.article_id'] = $article_id;
            $where['c.is_show'] = 1;
            $list = $this->db->select("c.*,u1.nickname comment_nickname,u1.head_img comment_head_img,u2.nickname reply_nickname,u2.head_img reply_head_img")
                            ->from("bbs_article_comment c")
                            ->join("users_info u1", "u1.user_id = c.uid", "left")
                            ->join("users_info u2", "u2.user_id = c.repay_user_id", "left")
                            ->where($where)->order_by("id desc")->limit($records_per_page, $currentPage * $records_per_page)->get()->result_array();
            $html = "";
            foreach ($list as $key => $val) {
                $uuid = encrypt_user_id($val['uid']);
                $is_self = $this->user_id == $val['uid'] ? 1 : 0;
                $lengther = mb_strlen($val['content'], "utf8");
                $show_more = $lengther > 70 ? "<a href='javascript:;' class='all col-red'>展开↓</a>" : "";
                if ($val['repay_user_id']) {
                    $reply_str = '<p class="text mt5 publicText">回复<a href="' . site_url("u/" . encrypt_user_id($val['repay_user_id'])) . '" class="col-red">' . $val['reply_nickname'] . '</a>：' . $val['content'] . '</p>' . $show_more;
                } else {
                    $reply_str = '<p class="text mt5 publicText">' . $val['content'] . '</p>' . $show_more;
                }
                $val['comment_head_img'] = strstr($val['comment_head_img'], "http") ? $val['comment_head_img'] : $this->img_host . $val['comment_head_img'];
                $val['reply_head_img'] = strstr($val['reply_head_img'], "http") ? $val['reply_head_img'] : $this->img_host . $val['reply_head_img'];
                $reply_btn_str = "<a href='javascript:;' class='publicText _reply' onclick=\"reply_comment_fn({comment_id:" . encrypt_comment_id($val['id']) . ",commenter_name:'$val[comment_nickname]',commenter_uid:$uuid});\">回复</a>";
                $html .= '<li class="f-cb ptb10" id="comment-' . encrypt_comment_id($val['id']) . '" data-cid="' . encrypt_comment_id($val['id']) . '" data->
                                <a href="' . site_url("u/" . encrypt_user_id($val['uid'])) . '" class="fl head-img"><img src="' . $val['comment_head_img'] . '"/></a>
                                <div class="pl45">
                                    <div class="comments-menu">
                                        <div class="menuToggle icon-menu iconfont fr">&#xe6a0;</div>
                                        <div class="menu-toggle">
                                            <b></b>
                                            ' . ($is_self ? '<a href="javascript:;" class="delete-jq" onclick="delete_comment_act({comment_id:' . encrypt_comment_id($val['id']) . ',obj:this});">删除</a>' : "") . '
                                            ' . $reply_btn_str . '
                                            <a href="javascript:;" class="publicReport _report" data-rel="http://www.tan66.com/p/' . encrypt_article_id($val['article_id']) . '/comments/' . encrypt_comment_id($val['id']) . '.html">举报</a>
                                        </div>
                                    </div>
                                    <a href="' . site_url("u/" . encrypt_user_id($val['uid'])) . '" class="name">' . $val['comment_nickname'] . '<img src="/static/weixin/img/vip/vip1.png"/></a>
                                    <p class="time mt5">' . $this->set_time_three($val['create_time']) . '</p>' . $reply_str . '
                                </div>
                            </li>';
            }
            echo $html;
            die;
        }
    }

    //文章点赞
    function art_like_num_add() {
        $this->is_login();
        if ($_POST) {
            $article_id = isset($_POST['article_id']) ? trim($_POST['article_id']) : 0;
            $article_id = decrypt_article_id($article_id);
            $article = $this->db->select("id,title,authorid,likes")->from("bbs_article")->where(array("id" => $article_id))->get()->row_array();
            if (!$article) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "文章不存在或已被删除";
                echo JSON($mess);
                exit;
            }
            $flag = $this->db->select("*")->from("bbs_like")->where(array("user_id" => $this->user_id, "article_id" => $article_id))->order_by("create_time desc")->get()->num_rows();
            if ($flag) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "已点赞";
                echo JSON($mess);
                exit;
            }

            $data = array();
            $data['article_id'] = $article_id;
            $data['user_id'] = $this->user_id;
            $data['create_time'] = time();
            $this->bbs_detail_model->insert_article_like($data);
            //发送消息
            $this->insert_notice(array("user_id" => $this->user_id, "recieve_id" => $article['authorid'], "operator_id" => $article_id, "event_type" => "event_like_article", "is_show" => 1, "type" => "article"));

//            $behavior = $this->bbs_account_model->check_behavior(array("user_id"=>$this->bbs_userinfo['user_id'],"operator_id"=>$article_id,"event_type"=>"event_like_article"));
//            if($behavior==null){
//            //更新个人动态
//            $this->insert_behavior(array("user_id"=>$this->bbs_userinfo['user_id'],"operator_id"=>$article_id,"event_type"=>"event_like_article","is_show"=>1));
//            }

            $errmes['reqStatus'] = true;
            echo JSON($errmes);
            exit;
        }
    }

    //添加、取消文章收藏
    function cancel_favor_act() {
        $this->is_login();
        if ($_POST) {
            $article_id = isset($_POST['collectId']) ? trim($_POST['collectId']) : 0;
            $article_id = decrypt_article_id($article_id);
            $is_favor = isset($_POST['is_favor']) ? trim($_POST['is_favor']) : 0;
            $art = $this->db->select("id,title,authorid")->from("bbs_article")->where(array("id" => $article_id))->get()->row_array();
            if (!$art) {
                $mess['reqStatus'] = false;
                $mess['errorCode'] = 1001;
                $mess['errorMsg'] = "文章不存在或已被删除";
                echo JSON($mess);
                exit;
            }
            if ($art['authorid'] == $this->user_id) {
                $mess['reqStatus'] = false;
                $mess['errorCode'] = 1001;
                $mess['errorMsg'] = "不能收藏自己的文章哦";
                echo JSON($mess);
                exit;
            }
            if ($is_favor) {//添加
                $status = $this->db->select("f.*")->from("bbs_favorite f")->where(array("f.user_id" => $this->user_id, "f.article_id" => $article_id, "f.is_del" => 0))->order_by("f.create_time desc")->get()->row_array();
                if ($status) {
                    $this->db->trans_begin();
                    $query1 = $this->db->query("update tan_bbs_favorite set is_del = 1 where user_id = " . $this->user_id . " and article_id = " . $article_id);
                    $query2 = $this->db->query("update tan_bbs_count set favor_count = favor_count + 1 where user_id = " . $this->user_id);

                    if ($query1 && $query2) {
                        $this->db->trans_commit();
                        $mess['reqStatus'] = true;
                        echo JSON($mess);
                        exit;
                    } else {
                        $this->db->trans_rollback();
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "操作失败，请稍后重试";
                        echo JSON($mess);
                        exit;
                    }
                } else {
                    $data = array();
                    $data['article_id'] = $article_id;
                    $data['user_id'] = $this->user_id;
                    $data['author_id'] = $art['authorid'];
                    $data['is_del'] = 1;
                    $data['create_time'] = time();

                    $this->db->trans_begin();
                    $this->db->insert("bbs_favorite", $data);
                    $query1 = $this->db->affected_rows();
                    $query2 = $this->db->query("update tan_bbs_count set favor_count = favor_count + 1 where user_id = " . $this->user_id);
                    if ($query1 && $query2) {
                        $this->db->trans_commit();
                        //发送消息
                        $this->insert_notice(array("user_id" => $this->user_id, "recieve_id" => $art['authorid'], "operator_id" => $article_id, "event_type" => "event_collect_article", "type" => "article", "is_show" => 1));

                        $mess['reqStatus'] = true;
                        echo JSON($mess);
                        exit;
                    } else {
                        $this->db->trans_rollback();
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "操作失败，请稍后重试";
                        echo JSON($mess);
                        exit;
                    }
                }
//                $behavior = $this->bbs_account_model->check_behavior(array("user_id"=>$this->bbs_userinfo['user_id'],"operator_id"=>$author_id,"event_type"=>"event_collect_article"));
//                if($behavior==null){
//                    //更新个人动态
//                    $this->insert_behavior(array("user_id"=>$this->bbs_userinfo['user_id'],"operator_id"=>$author_id,"event_type"=>"event_collect_article","is_show"=>1));
//                }
            } else {//取消操作
                $status = $this->db->select("f.*")->from("bbs_favorite f")->where(array("f.user_id" => $this->user_id, "f.article_id" => $article_id))->order_by("f.create_time desc")->get()->row_array();
                if (!$status) {
                    $mess['reqStatus'] = false;
                    $mess['errorCode'] = 1001;
                    $mess['errorMsg'] = "非法操作";
                    echo JSON($mess);
                    exit;
                }
                $this->db->trans_begin();
                $query1 = $this->db->query("update tan_bbs_favorite set is_del = 0 where user_id = " . $this->user_id . " and article_id = " . $article_id);
                $query2 = $this->db->query("update tan_bbs_count set favor_count = favor_count - 1 where user_id = " . $this->user_id);

                if ($query1 && $query2) {
                    $this->db->trans_commit();
                    $mess['reqStatus'] = true;
                    echo JSON($mess);
                    exit;
                } else {
                    $this->db->trans_rollback();
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "操作失败，请稍后重试";
                    echo JSON($mess);
                    exit;
                }
            }
        }
    }

    //关注作者
    function cancel_fan_act() {
        if ($_POST) {
            $this->is_login();
            $author_id = isset($_POST['author_id']) ? trim($_POST['author_id']) : 0;
            $author_id = decrypt_user_id($author_id);
            $is_fan = isset($_POST['is_fan']) ? trim($_POST['is_fan']) : 0;
            if ($author_id == $this->user_id) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "不能关注自己哦";
                echo JSON($mess);
                exit;
            }
            if ($is_fan) {//添加
                $status = $this->db->select("f.*")->from("bbs_fans f")->where(array("f.followuid" => $this->user_id, "f.user_id" => $author_id, "f.is_del" => 0))->order_by("f.create_time desc")->get()->row_array();
                if ($status) {
                    $this->db->trans_begin();
                    $query1 = $this->db->query("update tan_bbs_fans set is_del = 1 where followuid = " . $this->user_id . " and user_id = " . $author_id);
                    $query2 = $this->db->query("update tan_bbs_count set fans_count = fans_count + 1 where user_id = " . $author_id);
                    $query3 = $this->db->query("update tan_bbs_count set following_count = following_count + 1 where user_id = " . $this->user_id);

                    if ($query1 && $query2 && $query3) {
                        $this->db->trans_commit();
                        $mess['reqStatus'] = true;
                        echo JSON($mess);
                        exit;
                    } else {
                        $this->db->trans_rollback();
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "操作失败，请稍后重试";
                        echo JSON($mess);
                        exit;
                    }
                } else {
                    $data = array();
                    $data['followuid'] = $this->user_id;
                    $data['user_id'] = $author_id;
                    $data['is_del'] = 1;
                    $data['create_time'] = time();

                    $this->db->trans_begin();
                    $this->db->insert("bbs_fans", $data);
                    $query1 = $this->db->affected_rows();
                    $query2 = $this->db->query("update tan_bbs_count set fans_count = fans_count + 1 where user_id = " . $author_id);
                    $query3 = $this->db->query("update tan_bbs_count set following_count = following_count + 1 where user_id = " . $this->user_id);
                    if ($query1 && $query2 && $query3) {
                        $this->db->trans_commit();


                        //发送消息通知
                        $this->insert_notice(array("user_id" => $this->user_id, "recieve_id" => $author_id, "operator_id" => 0, "event_type" => "event_focus_author", "is_show" => 1, "type" => "system"));
                        //更新个人动态
                        //$this->insert_behavior(array("user_id"=>$this->bbs_userinfo['user_id'],"operator_id"=>$author_id,"event_type"=>"event_focus_author","is_show"=>1,"type"=>"system"));

                        $mess['reqStatus'] = true;
                        echo JSON($mess);
                        exit;
                    } else {
                        $this->db->trans_rollback();
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "操作失败，请稍后重试";
                        echo JSON($mess);
                        exit;
                    }
                }
            } else {//删除
                $status = $this->db->select("f.*")->from("bbs_fans f")->where(array("f.followuid" => $this->user_id, "f.user_id" => $author_id))->order_by("f.create_time desc")->get()->row_array();
                if (!$status) {
                    $mess['reqStatus'] = false;
                    $mess['errorCode'] = 1001;
                    $mess['errorMsg'] = "非法操作";
                    echo JSON($mess);
                    exit;
                }
                $this->db->trans_begin();
                $query1 = $this->db->query("update tan_bbs_fans set is_del = 0 where id = " . $status['id']);
                $query2 = $this->db->query("update tan_bbs_count set following_count = following_count - 1 where user_id = " . $this->user_id);
                $query3 = $this->db->query("update tan_bbs_count set fans_count = fans_count - 1 where user_id = " . $author_id);

                if ($query1 && $query2 && $query3) {
                    $this->db->trans_commit();
                    $mess['reqStatus'] = true;
                    echo JSON($mess);
                    exit;
                } else {
                    $this->db->trans_rollback();
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "操作失败，请稍后重试";
                    echo JSON($mess);
                    exit;
                }
            }
        }
    }

    //增加文章阅读数
    function art_read_num_add() {
        if ($_GET) {
            $article_id = isset($_GET['article_id']) ? trim($_GET['article_id']) : 0;
            $uuid = isset($_GET['uuid']) ? trim($_GET['uuid']) : 0;
            $article_id = decrypt_article_id($article_id);
            $uuid = decrypt_user_id($uuid);
            if ($uuid == $this->user_id) {
                $mess['reqStatus'] = false;
                echo JSON($mess);
                exit;
            }
            $article = $this->db->select("id,title,authorid,readnum")->from("bbs_article")->where(array("id" => $article_id))->get()->row_array();
            if (!$article) {
                $mess['reqStatus'] = false;
                echo JSON($mess);
                exit;
            }
            if ($article['authorid'] == $this->user_id) {
                $mess['reqStatus'] = false;
                echo JSON($mess);
                exit;
            }
            $this->db->trans_begin();
            $query = $this->db->query("update tan_bbs_article set readnum = readnum + 1 where id = " . $article_id);
            if ($query) {
                $this->db->trans_commit();

                $mess['reqStatus'] = true;
                echo JSON($mess);
                exit;
            } else {
                $this->db->trans_rollback();
                $mess['reqStatus'] = false;
                echo JSON($mess);
                exit;
            }
        }
    }

    //添加文章评论
    function ajax_comment_add() {
        $this->is_login();
        if ($_POST) {
            $article_id = isset($_REQUEST['article_id']) ? trim($_REQUEST['article_id']) : 0; //文章id
            $content = isset($_REQUEST['content']) ? trim($_REQUEST['content']) : ""; //评论内容
            $author_id = isset($_REQUEST['author_id']) ? trim($_REQUEST['author_id']) : 0; //文章作者
            $comment_id = isset($_REQUEST['comment_id']) ? trim($_REQUEST['comment_id']) : 0; //回复的评论id
            $comment_uid = isset($_REQUEST['comment_uid']) ? trim($_REQUEST['comment_uid']) : 0; //回复的评论者
            $card_index = isset($_REQUEST['card']) ? trim($_REQUEST['card']) : 0; //回复的卡通图片

            $article_id = decrypt_article_id($article_id);
            $author_id = decrypt_user_id($author_id);
            $comment_id = $comment_id ? decrypt_comment_id($comment_id) : 0;
            $comment_uid = $comment_uid ? decrypt_user_id($comment_uid) : 0;
            //获取文章
            $article = $this->db->select("id,authorid,status,commentnum")->from("bbs_article")->where(array("id" => $article_id))->order_by("create_time desc")->get()->row_array();

            if (!$article) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "文章不存在或已被删除，无法评论哦";
                echo JSON($mess);
                exit;
            }
            if ($article['authorid'] != $author_id) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);
                exit;
            }
            if ($comment_id) {//获取评论
                $comment = $this->db->select("id,uid,content")->from("bbs_article_comment")->where(array("id" => $comment_id, "is_show" => 1))->order_by("create_time desc")->get()->row_array();
                if (!$comment) {
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "此评论不存在或已删除，无法回复哦";
                    echo JSON($mess);
                    exit;
                }
                //如果前台获取的回复评论作者不等于真实评论作者，则视为非法操作
                if ($comment['uid'] != $comment_uid) {
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "非法操作";
                    echo JSON($mess);
                    exit;
                }
            }

            if (strip_tags(trim($content)) == "") {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "回复内容不能为空！";
                echo JSON($mess);
                exit;
            }

            $is_self = $author_id == $this->user_id;

            $data = array();
            $data["uid"] = $this->user_id;
            $data["article_id"] = $article_id;
            $data["authorid"] = $author_id;
            $data["content"] = strip_tags($content);
            $data["create_time"] = time();
            $data["month"] = date("Ym");
            $data["day"] = date("Ymd");
            $data["repay_user_id"] = $comment_uid ? $comment_uid : 0;
            $data["cid"] = $comment_id ? $comment_id : 0;
            $data["type"] = $comment_id ? 1 : 0;
            $data["card_index"] = $card_index;

            $this->db->trans_begin();
            $this->db->insert("bbs_article_comment", $data);
            $insert_id = $this->db->insert_id();
//            $query1 = $this->db->query("update tan_bbs_count set reply_count = reply_count + 1 where user_id = ".$this->bbs_userinfo['user_id']);
            $query2 = $this->db->query("update tan_bbs_article set commentnum = commentnum + 1 where id = " . $article_id);

            if ($insert_id && $query2) {
                $this->db->trans_commit();

                //发送消息通知
                if ($comment_id) {
                    //回复评论
                    $this->insert_notice(array("user_id" => $this->user_id, "recieve_id" => $comment_uid, "operator_id" => $insert_id, "event_type" => "event_comment_article", "type" => "article", "is_show" => 1));
                } else {
                    //评论文章
                    if (!$is_self) {
                        $this->insert_notice(array("user_id" => $this->user_id, "recieve_id" => $author_id, "operator_id" => $insert_id, "event_type" => "event_reply_article", "type" => "article", "is_show" => 1));
                    }
                }

//                //更新个人动态
//                $this->insert_behavior(array("user_id"=>$this->bbs_userinfo['user_id'],"operator_id"=>$result,"event_type"=>"event_comment_article","is_show"=>1));
                $item = $this->db->select("c.*,u1.nickname comment_nickname,u1.head_img comment_head_img,u2.nickname reply_nickname,u2.head_img reply_head_img")
                                ->from("bbs_article_comment c")
                                ->join("users_info u1", "u1.user_id = c.uid", "left")
                                ->join("users_info u2", "u2.user_id = c.repay_user_id", "left")
                                ->where(array('c.id' => $insert_id))->order_by("id desc")->limit(1)->get()->row_array();

                $uuid = encrypt_user_id($item['uid']);


                $lengther = mb_strlen($item['content'], "utf8");
                $show_more = $lengther > 70 ? "<a href='javascript:;' class='all col-red'>展开↓</a>" : "";

                if ($item['repay_user_id']) {
                    $reply_str = '<p class="text mt5 publicText">回复<a href="' . site_url("u/" . encrypt_user_id($item['repay_user_id'])) . '" class="col-red">' . $item['reply_nickname'] . '</a>：' . $item['content'] . '</p>' . $show_more;
                } else {
                    $reply_str = '<p class="text mt5 publicText">' . $item['content'] . '</p>' . $show_more;
                }

                $item['comment_head_img'] = strstr($item['comment_head_img'], "http") ? $item['comment_head_img'] : $this->img_host . $item['comment_head_img'];


                $reply_btn_str = "<a href='javascript:;' class='publicText _reply' onclick=\"reply_comment_fn({comment_id:" . encrypt_comment_id($item['id']) . ",commenter_name:'$item[comment_nickname]',commenter_uid:$uuid});\">回复</a>";
                $html = '<li class="f-cb ptb10" id="comment-' . encrypt_comment_id($item['id']) . '" data-cid="' . encrypt_comment_id($item['id']) . '" data->
                            <a href="' . site_url("u/" . encrypt_user_id($item['uid'])) . '" class="fl head-img"><img src="' . $item['comment_head_img'] . '"/></a>
                            <div class="pl45">
                                <div class="comments-menu">
                                    <div class="menuToggle icon-menu iconfont fr">&#xe6a0;</div>
                                    <div class="menu-toggle">
                                        <b></b>
                                        <a href="javascript:;" class="delete-jq" onclick="delete_comment_act({comment_id:' . encrypt_comment_id($item['id']) . ',obj:this});">删除</a>
                                        ' . $reply_btn_str . '
                                        <a href="javascript:;" class="publicReport _report" data-rel="http://www.tan66.com/p/' . encrypt_article_id($item['article_id']) . '/comments/' . encrypt_comment_id($item['id']) . '.html">举报</a>
                                    </div>
                                </div>
                                <a href="' . site_url("u/" . encrypt_user_id($item['uid'])) . '" class="name">' . $item['comment_nickname'] . '<img src="../static/default/img/vip/vip1.png"/></a>
                                <p class="time mt5">' . $this->set_time_three($item['create_time']) . '</p>' . $reply_str . '
                            </div>
                        </li>';


                $mess['reqStatus'] = true;
                $mess['htmlData'] = $html;
                $mess['commentNum'] = $article['commentnum'] + 1;
                echo json_encode($mess, JSON_HEX_TAG);
                exit;
            } else {
                $this->db->trans_rollback();
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作失败，请稍后重试";
                echo JSON($mess);
                exit;
            }
        }
    }

    //删除文章评论
    function cancel_comment_act() {
        $this->is_login();
        if ($_POST) {
            $comment_id = isset($_POST['comment_id']) ? trim($_POST['comment_id']) : 0;
            $comment_id = decrypt_comment_id($comment_id);
            $comment = $this->db->select("*")->from("bbs_article_comment")->where(array("id" => $comment_id, "is_show" => 1))->order_by("id desc")->get()->row_array();
            if (!$comment) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "评论已删除或不存在";
                echo JSON($mess);
                exit;
            }

            if ($comment['uid'] != $this->user_id) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);
                exit;
            }
            $article = $this->db->select("commentnum")->from("bbs_article")->where(array("id" => $comment['article_id'], "status" => 1))->order_by("id desc")->get()->row_array();
            $this->db->trans_begin();
            $query1 = $this->db->query("update tan_bbs_article_comment set is_show = 0 where id = " . $comment_id);
            $query2 = $this->db->query("update tan_bbs_article set commentnum = commentnum - 1 where id = " . $comment['article_id']);
            if ($query1 && $query2) {
                $this->db->trans_commit();
                $mess['reqStatus'] = true;
                $mess['commentnum'] = $article['commentnum'] - 1;
                echo JSON($mess);
                exit;
            } else {
                $this->db->trans_rollback();
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作失败，请稍后重试";
                echo JSON($mess);
                exit;
            }
        }
    }

    //显示空间内评论信息
    function get_comment_json() {
        $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
        $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
        $uuid = decrypt_user_id($uuid);
        $where = array();
        $where['uid'] = $uuid;
        $where['is_show'] = 1;
        $is_self = $uuid == user_id;
        $records_per_page = 10;
        $list = $this->db->select("c.*,a.title,a.commentnum,u1.nickname authorid_nickname,u1.head_img authorid_head_img,u2.nickname reply_nickname")
                        ->from("bbs_article_comment c")
                        ->join("users_info u1", "u1.user_id = c.authorid", "left")
                        ->join("users_info u2", "u2.user_id = c.repay_user_id", "left")
                        ->join("bbs_article a", "a.id = c.article_id", "left")
                        ->where($where)->order_by("id desc")->limit($records_per_page, $pageIndex * $records_per_page)->get()->result_array();
        $html = "";
        foreach ($list as $key => $val) {
            $authorid = encrypt_user_id($val['authorid']);
            $val["content"] = mb_strlen($val['content'], "utf8") > 100 ? mb_strcut($val['content'], 0, 120, "utf8") . "..." : $val['content'];
            //$val['comment_url'] = web_url("p/".encrypt_article_id($val['article_id'])."/comments/".encrypt_comment_id($val['id']));

            $val['authorid_head_img'] = strstr($val['authorid_head_img'], "http") ? $val['authorid_head_img'] : $this->img_host . $val['authorid_head_img'];
            $html .= "<div class='pb10 border-bottom-sm'>
            	 		<a href='" . site_url("p/" . encrypt_article_id($val['article_id'])) . "' class='con disblock'></a>
                        <div class='plr15'>
                            <div class='user-head f-cb ptb10'>
                                <a href='" . site_url("u/" . $authorid) . "'><img src='$val[authorid_head_img]' class='head fl'/></a>
                                <span class='name fl ml5'>$val[authorid_nickname]</span>
                                <img src='/static/weixin/img/vip/vip1.png' class='badge fl ml5'/>
                            </div>
                            <a href='" . site_url("p/" . encrypt_article_id($val['article_id'])) . "' class='text'>$val[title]</a>
                            <div class='num f-cb mt5'>
                                <p class='time fl col-grey999'>" . date("m-d H:s", $val['create_time']) . "</p>
                                <font class='iconfont fr col-grey999'>&#xe675;$val[commentnum]</font>
                            </div>
                        </div>
                        <p class='textnum60 bj-grey ptb10 plr15'>$val[content]</p>
                    </div>";
        }
        echo $html;
        die;
    }

    //显示个人中心我的文章
    function get_arts_json() {
        $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
        $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
        $uuid = decrypt_user_id($uuid);
        $where = array();
        $where['authorid'] = $uuid;
        $where['show'] = 1;
        $records_per_page = 10;
        $list = $this->db->select("title,status,thumb,create_time,id,commentnum,readnum")
                        ->from("bbs_article")
                        ->where($where)->order_by("status asc,create_time desc")->limit($records_per_page, $pageIndex * $records_per_page)->get()->result_array();
        $html = "";
        foreach ($list as $key => $val) {
            $id = encrypt_article_id($val['id']);
            if ($val['status'] == 0) {
                $html .= "<section>
                                <a href='" . site_url("p/upub/" . $id) . "' class='article-box f-cb'>
                                    <div class='pic fl'>
                                        <img src='$val[thumb]' alt=''>
                                    </div>
                                    <div class='article-detail'>
                                        <p class='title'>$val[title]</p>
                                        <p class='state f-cb'>
                                            <span class='fl'>" . date("Y-m-d H:s", $val['create_time']) . "</span>
                                            <i class='fr iconfont passing'>
                                                &#xe64b;<span>审核中</span>
                                            </i>
	                                     </p>
                                    </div>
                                </a>
                            </section>";
            } elseif ($val['status'] == 1) {
                $html .= "<section>
                                <a href='" . site_url("p/" . $id) . "' class='article-box f-cb'>
                                    <div class='pic fl'>
                                        <img src='$val[thumb]' alt=''>
                                    </div>
                                    <div class='article-detail'>
                                        <p class='title'>$val[title]</p>
                                        <p class='state f-cb'>
                                            <span class='fl'>" . date("Y-m-d H:s", $val['create_time']) . "</span>
                                           <span class='fr'>$val[commentnum]</span><font class='iconfont fr'>&#xe675;</font>
                                            <span class='fr mr8'>$val[readnum]</span><font class='iconfont fr mr3'>&#xe60a;</font>
	                                    </p>
                                    </div>
                                </a>
                            </section>";

                /* $status_str ="<p class='state f-cb'>
                  <span class='fl'>". date("Y-m-d H:s",$val['create_time'])."</span>
                  <span class='fr'>$val[commentnum]</span><font class='iconfont fr'>&#xe675;</font>
                  <span class='fr mr8'>$val[readnum]</span><font class='iconfont fr mr3'>&#xe60a;</font>
                  </p>"; */
            } elseif ($val['status'] == 2) {
                $html .= "<section>
                                <a href='" . site_url("p/" . $id) . "' class='article-box f-cb'>
                                    <div class='pic fl'>
                                        <img src='$val[thumb]' alt=''>
                                    </div>
                                    <div class='article-detail'>
                                        <p class='title'>$val[title]</p>
                                        <p class='state f-cb'>
                                        <span class='fl'>" . date("Y-m-d H:s", $val['create_time']) . "</span>
                                            <i class='fr iconfont unpass'>
                                                &#xe8a3;<span>未通过</span>
                                            </i>
	                                    </p>
                                    </div>
                                </a>
                            </section>";
            }
        }
        echo $html;
        die;
    }

    //显示他人中心文章
    function get_other_arts_json() {
        $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
        $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
        $uuid = decrypt_user_id($uuid);
        $where = array();
        $where['authorid'] = $uuid;
        $where['show'] = 1;
        $where['status'] = 1;
        $records_per_page = 10;
        $list = $this->db->select("title,status,thumb,create_time,id,commentnum,readnum")
                        ->from("bbs_article")
                        ->where($where)->order_by("create_time desc")->limit($records_per_page, $pageIndex * $records_per_page)->get()->result_array();
        $html = "";
        foreach ($list as $key => $val) {
            $id = encrypt_article_id($val['id']);
            $html .= "<section>
                        <a href='" . site_url("p/" . $id) . "' class='article-box f-cb'>
                            <div class='pic fl'>
                                <img src='$val[thumb]' alt=''>
                            </div>
                            <div class='article-detail'>
                                <p class='title'>$val[title]</p>
                                <p class='state f-cb'>
                                    <span class='fl'>" . date("Y-m-d H:s", $val['create_time']) . "</span>
                                   <span class='fr'>$val[commentnum]</span><font class='iconfont fr'>&#xe675;</font>
                                    <span class='fr mr8'>$val[readnum]</span><font class='iconfont fr mr3'>&#xe60a;</font>
                                    </p>
                            </div>
                        </a>
                    </section>";
        }
        echo $html;
        die;
    }

    //个人中心 我的提问
    function get_question_json() {
        if ($_POST) {
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
            $uuid = decrypt_user_id($uuid);
            $records_per_page = 10;
            $list = $this->db->query("select id,title,answernum,readnum,focusnum,create_time,answer_id from tan_bbs_wenda where questioner_id = $uuid  order by id desc limit " . ($pageIndex * $records_per_page) . "," . $records_per_page)->result_array();
            $html = "";
            foreach ($list as $key => $val) {
                $html .= "<li>
                				<a href='" . site_url("wenda/" . encrypt_wenda_id($val[id])) . "'></a>
                                <p>$val[title]</p>
                                <div class='con'>
                                        <time>" . date("Y-m-d H:s", $val['create_time']) . "</time>
                                        <font class='iconfont ml5'>&#xe675;<span>$val[answernum]</span></font>
                                        <font class='iconfont ml5'>&#xe60a;<span>$val[readnum]</span></font>
                                        <font class='iconfont fr mt2'><span>$val[focusnum]</span>&#xe654;</font>
                                </div>
                        </li>";
            }
            echo $html;
            die;
        }
    }

    //个人中心 我的回答
    function get_answer_json() {
        if ($_POST) {
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
            $uuid = decrypt_user_id($uuid);
            $records_per_page = 10;
            $list = $this->db->query("select a.id,a.content,a.wenda_id,a.commentnum,a.likes,a.wenda_uid,a.create_time,a.is_answer,w.title from tan_bbs_wenda_answer a left join tan_users_info u on u.user_id = a.wenda_uid left join tan_bbs_wenda w on a.wenda_id = w.id where a.user_id = $uuid  order by a.id desc limit " . ($pageIndex * $records_per_page) . "," . $records_per_page)->result_array();
            $html = "";
            foreach ($list as $key => $val) {
                $html .= "<li>
                			<a href='" . site_url("wenda/" . encrypt_wenda_id($val[wenda_id])) . "'></a>
							<h4>$val[title]</h4>
							<div class='my-answer'><p class='textnum50'>" . mb_strcut((strip_tags(trim($val[content]))), 0, 150, "utf-8") . "</p></div>
							<div class='answer-info f-cb'>
								<time>" . date("Y-m-d H:s", $val['create_time']) . "</time>
								<font class='iconfont fr'>&#xe675;<span>$val[commentnum]</span></font>
								<font class='iconfont fr praise'>&#xe615;<span>$val[likes]</span></font>
							</div>
						</li>";
            }
            echo $html;
            die;
        }
    }

    //个人中心 我的关注
    function get_follow_json() {
        if ($_POST) {
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $uuid = isset($_REQUEST['uuid']) ? trim($_REQUEST['uuid']) : 0;
            $uuid = decrypt_user_id($uuid);
            $records_per_page = 10;
            $list = $this->db->query("select c.wenda_id,c.wenda_uid,w.title,w.create_time,w.answer_id,w.answernum,w.readnum,w.focusnum,u.nickname,u.head_img from tan_bbs_wenda_care c left join tan_users_info u on u.user_id = c.wenda_uid left join tan_bbs_wenda w on c.wenda_id = w.id  where c.user_id = $uuid and c.is_del = 1 order by c.id desc limit " . ($pageIndex * $records_per_page) . "," . $records_per_page)->result_array();
            $html = "";
            foreach ($list as $key => $val) {
                $val['head_img'] = strstr($val['head_img'], "http") ? $val['head_img'] : $this->img_host . $val['head_img'];
                $html .= "<li>
                				<a href='" . site_url("wenda/" . encrypt_wenda_id($val[wenda_id])) . "'></a>
                                <p>$val[title]</p>
                                <div class='info'>
                                        <font><img src='$val[head_img]' alt='' /><span class='nickname'>$val[nickname]~~~~~~</span></font>
                                        <font class='iconfont ml5'>&#xe675;<span>$val[answernum]</span></font>
                                        <font class='iconfont ml5'>&#xe60a;<span>$val[readnum]</span></font>
                                        <font class='fr iconfont'><span class='mr2'>$val[focusnum]</span>&#xe6f8;</font>
                                </div>
                        </li>";
            }
            echo $html;
            die;
        }
    }

    //获取更多问答
    function ajax_fetch_more_wenda_json() {
        if ($_POST) {
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $dType = isset($_REQUEST['dType']) ? trim($_REQUEST['dType']) : "hot";
            $records_per_page = 10;
            $dataOffset = 15 + $pageIndex * $records_per_page;
            if ($dType == "hot") {
                $where = "w.hot = 1 and w.status = 1 and w.is_show = 1 order by w.sort desc,w.id desc";
            } elseif ($dType == "lastest") {
                $where = "w.is_show = 1 and w.status = 1 order by w.id desc";
            } elseif ($dType == "wait") {
                $where = "w.answernum = 0 and w.status = 1 and w.is_show = 1 order by w.sort desc,w.id desc";
            } elseif ($dType == "act") {
                $where = "w.tags_name like '%溜溜活动%' and w.status = 1 and w.is_show = 1 order by w.id desc";
            }
            $query_params = "w.id,w.questioner_id,w.title,w.summary,w.readnum,w.answernum,w.likes,w.answer_id,w.answer_uid,i.head_img,i.nickname";
            $list = $this->db->query("select $query_params from tan_bbs_wenda w left join tan_users_info i on i.user_id = w.questioner_id where $where limit $dataOffset,$records_per_page")->result_array();
            $html = "";
            foreach ($list as $key => $val) {
                $val['head_img'] = strstr($val['head_img'], "http") ? $val['head_img'] : $this->img_host . $val['head_img'];
                $answer = $this->db->query("select thumb,content,is_answer from tan_bbs_wenda_answer where wenda_id = $val[id] and is_show = 1 order by is_answer desc,likes desc limit 1")->row_array();
                if ($answer) {
                    $answer['content'] = mb_strcut(strip_tags($answer['content']), 0, 190, "utf8") . "...";
                }
                $html .= "<li class='border-bottom-lg'>";
                $html .= "<a href='" . site_url("wenda/" . encrypt_wenda_id($val['id'])) . "'>";
                $html .= "<p class='problem-title border-bottom-sm ptb5 plr15'>$val[title]</p>";
                $html .= "<div class='pt10 f-cb plr15'>";
                if ($answer['thumb']) {
                    $html .= "<div class='problem-img fl'><img src='" . $answer['thumb'] . "'/></div>";
                }
                $html .= "<p class='problem-text " . ($answer['thumb'] ? "pl105" : "") . "'>" . ($answer['is_answer'] ? "最佳答案：" : "") . ($answer ? $answer['content'] : $val['content'] . "...") . "</p>";
                $html .= "</div>";
                $html .= "<div class='user-head ptb5 plr15 f-cb'>";
                $html .= "<div class='fl'>";
                $html .= "<img src='$val[head_img]' class='head fl'/>";
                $html .= "<span class='name fl ml5'>$val[nickname]</span>";
                $html .= "<img src='/static/weixin/img/vip/vip1.png' class='badge fl ml5'/>";
                $html .= "</div>";
                $html .= "<font class='iconfont fr ml10'><i>$val[answernum]</i>&#xe675;</font>";
                $html .= "<font class='iconfont fr ml10'><i>$val[focusnum]</i>&#xe654;</font>";
                $html .= "<font class='iconfont fr'><i>$val[readnum]</i>&#xe60a;</font>";
                $html .= "</div>";
                $html .= "</a>";
                $html .= "</li>";
            }
            echo $html;
            die;
        }
    }

    //获取首页问答
    function ajax_fetch_wenda_json() {
        if ($_POST) {
            $dType = isset($_REQUEST['dType']) ? trim($_REQUEST['dType']) : "hot";
            $records_per_page = 10;
            if ($dType == "hot") {
                $where = "w.hot = 1 and w.status = 1 and w.is_show = 1 order by w.sort desc,w.id desc";
            } elseif ($dType == "lastest") {
                $where = "w.is_show = 1 and w.status = 1 order by w.id desc";
            } elseif ($dType == "wait") {
                $where = "w.answernum = 0 and w.status = 1 and w.is_show = 1 order by w.sort desc,w.id desc";
            } elseif ($dType == "act") {
                $where = "w.tags_name like '%溜溜活动%' and w.status = 1 and w.is_show = 1 order by w.id desc";
            }
            $query_params = "w.id,w.questioner_id,w.title,w.summary,w.readnum,w.answernum,w.likes,w.answer_id,w.answer_uid,i.head_img,i.nickname";
            $list = $this->db->query("select $query_params from tan_bbs_wenda w left join tan_users_info i on i.user_id = w.questioner_id where $where limit 15")->result_array();
            $html = "";
            foreach ($list as $key => $val) {
                $val['head_img'] = strstr($val['head_img'], "http") ? $val['head_img'] : $this->img_host . $val['head_img'];
                $answer = $this->db->query("select thumb,content,is_answer from tan_bbs_wenda_answer where wenda_id = $val[id] and is_show = 1 order by is_answer desc,likes desc limit 1")->row_array();
                if ($answer) {
                    $answer['content'] = mb_strcut(strip_tags($answer['content']), 0, ($answer['thumb'] ? 120 : 150), "utf8") . "...";
                }
                $html .= "<li class='border-bottom-lg'>";
                $html .= "<a href='" . site_url("wenda/" . encrypt_wenda_id($val['id'])) . "'>";
                $html .= "<p class='problem-title border-bottom-sm ptb5 plr15'>$val[title]</p>";
                $html .= "<div class='pt10 f-cb plr15'>";
                if ($answer['thumb']) {
                    $html .= "<div class='problem-img fl'><img src='" . $answer['thumb'] . "'/></div>";
                }
                $html .= "<p class='problem-text " . ($answer['thumb'] ? "pl105" : "") . "'>" . ($answer['is_answer'] ? "最佳答案：" : "") . ($answer ? $answer['content'] . "..." : ($val['summary'] ? $val['summary'] . "..." : "")) . "</p>";
                $html .= "</div>";
                $html .= "<div class='user-head ptb5 plr15 f-cb'>";
                $html .= "<div class='fl'>";
                $html .= "<img src='$val[head_img]' class='head fl'/>";
                $html .= "<span class='name fl ml5'>$val[nickname]</span>";
                $html .= "<img src='/static/weixin/img/vip/vip1.png' class='badge fl ml5'/>";
                $html .= "</div>";
                $html .= "<font class='iconfont fr ml10'><i>$val[answernum]</i>&#xe675;</font>";
                $html .= "<font class='iconfont fr ml10'><i>$val[focusnum]</i>&#xe654;</font>";
                $html .= "<font class='iconfont fr'><i>$val[readnum]</i>&#xe60a;</font>";
                $html .= "</div>";
                $html .= "</a>";
                $html .= "</li>";
            }
            $result = array(
                "reqStatus" => true,
                "htmlData" => $html,
            );
            echo json_encode($result, JSON_HEX_TAG);
            die;
        }
    }

    //问答搜索下拉更多
    function ajax_search_more_wenda_json() {
        if ($_POST) {
            $kw = trim($_POST['keyWord']);
            $pageIndex = isset($_POST['pageIndex']) ? trim($_POST['pageIndex']) : 0;
            $records_per_page = 15;
            $limitIndex = 15 + $pageIndex * $records_per_page;
            $query_params = "w.id,w.title,w.questioner_id,w.readnum,w.answernum,w.create_time,w.focusnum,i.head_img,i.nickname";
            $list = $this->db->query("select $query_params from tan_bbs_wenda w left join tan_users_info i on i.user_id = w.questioner_id where w.title like '%$kw%' and w.status = 1 and w.is_show = 1 order by w.hot desc,w.sort desc limit $limitIndex,$records_per_page")->result_array();
            $html = "";
            foreach ($list as $key => $val) {
                $val['head_img'] = strstr($val['head_img'], "http") ? $val['head_img'] : $this->img_host . $val['head_img'];
                $val['detail_url'] = site_url("wenda/" . encrypt_wenda_id($val['id']));
                $val['space_url'] = site_url("u/" . encrypt_user_id($val['questioner_id']));
                $val['create_time'] = $this->set_time_three($val['create_time']);
                $val['title'] = str_replace($kw, "<span class='col-red'>$kw</span>", $val['title']);
                $html .= "<li class='ptb10 plr15 border-bottom-lg'>
                                <button class='iconfont fr mt5 col-grey999'><i>$val[focusnum]</i>&#xe654;</button>
                                <a href='$val[space_url]' class='user-head f-cb disblock'>
                                        <img src='$val[head_img]' class='head fl'/>
                                        <span class='name fl ml5'>$val[nickname]</span>
                                        <img src='/static/weixin/img/vip/vip1.png' class='badge fl ml5'/>
                                </a>
                                <a href='$val[detail_url]' class='disblock mt5'>
                                    <p class='txt pb5'>$val[title]</p>
                                    <font class='iconfont col-grey999'>&#xe675;<i>$val[answernum]</i></font>
                                    <font class='iconfont col-grey999 ml5'>&#xe60a;<i>$val[readnum]</i></font>
                                    <p class='time fr'>$val[create_time]</p>
                                </a>
                        </li>";
            }
            echo $html;
            die;
        }
    }

    //文章搜索页面
    function ajax_search_wenda_json() {
        if ($_POST) {
            $kw = trim($_POST['keyWord']);
            $query_params = "w.id,w.title,w.questioner_id,w.readnum,w.answernum,w.create_time,w.focusnum,i.head_img,i.nickname";
            $list = $this->db->query("select $query_params from tan_bbs_wenda w left join tan_users_info i on i.user_id = w.questioner_id where w.title like '%$kw%' and w.status = 1 and w.is_show = 1 order by w.hot desc,w.sort desc limit 15")->result_array();
            $html = "";
            foreach ($list as $key => $val) {
                $val['head_img'] = strstr($val['head_img'], "http") ? $val['head_img'] : $this->img_host . $val['head_img'];
                $val['detail_url'] = site_url("wenda/" . encrypt_wenda_id($val['id']));
                $val['space_url'] = site_url("u/" . encrypt_user_id($val['questioner_id']));
                $val['create_time'] = $this->set_time_three($val['create_time']);
                $val['title'] = str_replace($kw, "<span class='col-red'>$kw</span>", $val['title']);
                $html .= "<li class='ptb10 plr15 border-bottom-lg'>
                                <button class='iconfont fr mt5 col-grey999'><i>$val[focusnum]</i>&#xe654;</button>
                                <a href='$val[space_url]' class='user-head f-cb disblock'>
                                        <img src='$val[head_img]' class='head fl'/>
                                        <span class='name fl ml5'>$val[nickname]</span>
                                        <img src='/static/weixin/img/vip/vip1.png' class='badge fl ml5'/>
                                </a>
                                <a href='$val[detail_url]' class='disblock mt5'>
                                    <p class='txt pb5'>$val[title]</p>
                                    <font class='iconfont col-grey999'>&#xe675;<i>$val[answernum]</i></font>
                                    <font class='iconfont col-grey999 ml5'>&#xe60a;<i>$val[readnum]</i></font>
                                    <p class='time fr'>$val[create_time]</p>
                                </a>
                        </li>";
            }
            $result = array(
                "reqStatus" => true,
                "htmlData" => $html,
            );
            echo json_encode($result, JSON_HEX_TAG);
            die;
        }
    }

    //搜索问答标签
    function seach_wenda_tag() {
        $key_tag = isset($_GET['tag_key']) ? trim($_GET['tag_key']) : "";
        if (!$key_tag) {
            $mess['reqStatus'] = true;
            $mess['seachRes'] = "";
            echo JSON($mess);
            exit;
        }
        $key_tag = strtolower($key_tag); //将所有大写字母转为小写

        if (preg_match("/^[a-z0-9]+$/", $key_tag)) {//字母或数字查询
            if (strlen($key_tag) == 1) {
                $colum = "letter_first";
            } else {
                $colum = "letter_all";
            }
        } else {//其他条件查询
            $colum = "name";
        }
        $tags = $this->db->select("name,id")->from("bbs_wenda_tags")->where(array())->like($colum, $key_tag, 'both')->order_by("sort desc")->get()->result_array();
        $bbs_account = $this->db->query("select * from tan_bbs_account where user_id = " . $this->user_id . " order by id desc limit 1")->row_array();
        $seach_html = "";
        foreach ($tags as $key => $val) {
            if ($val['name'] == "溜溜活动" && !$bbs_account['is_official']) {
                continue;
            } else {
                $seach_html .= "<li  seach-name='" . $val['name'] . "' seach-tid='" . $val['id'] . "'>" . $val['name'] . "</li>";
            }
        }

        $mess['reqStatus'] = true;
        $mess['seachRes'] = $seach_html;
        echo json_encode($mess, JSON_HEX_TAG);
        die;
    }

    //关注问答
    function ajax_wd_care() {
        $this->is_login();
        if ($_POST) {
            $wenda_id = isset($_POST['wenda_id']) ? trim($_POST['wenda_id']) : 0;
            $uuid = isset($_POST['uuid']) ? trim($_POST['uuid']) : 0;
            $value = isset($_POST['value']) ? trim($_POST['value']) : 0;
            $wenda_id = decrypt_wenda_id($wenda_id);
            $uuid = decrypt_user_id($uuid);

            $wenda = $this->db->select("id,questioner_id,focusnum")->from("bbs_wenda")->where(array("id" => $wenda_id))->order_by("id asc")->get()->row_array();
            if (!$wenda) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);
                exit;
            }
            if ($wenda['questioner_id'] != $uuid) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);
                exit;
            }

            if ($wenda['questioner_id'] == $this->user_id) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "不能关注自己的问答哦";
                echo JSON($mess);
                exit;
            }

            if ($value) {//关注
                $status = $this->db->select("*")->from("bbs_wenda_care")->where(array("user_id" => $this->user_id, "wenda_id" => $wenda_id, "is_del" => 0))->order_by("id desc")->get()->row_array();
                if ($status) {
                    $this->db->trans_begin();
                    $query1 = $this->db->query("update tan_bbs_wenda_care set is_del = 1 where id = " . $status['id']);
                    $query2 = $this->db->query("update tan_bbs_wenda set focusnum = focusnum + 1 where id = " . $wenda_id);
                    $query3 = $this->db->query("update tan_bbs_count set follow_question_count = follow_question_count + 1 where user_id = " . $this->user_id);

                    if ($query1 && $query2 && $query3) {
                        $this->db->trans_commit();
                        $mess['reqStatus'] = true;
                        $mess['count'] = $wenda['focusnum'] + 1;

                        echo JSON($mess);
                        exit;
                    } else {
                        $this->db->trans_rollback();
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "操作失败，请稍后重试";
                        echo JSON($mess);
                        exit;
                    }
                } else {
                    $data = array();
                    $data['user_id'] = $this->user_id;
                    $data['wenda_id'] = $wenda_id;
                    $data['wenda_uid'] = $wenda['questioner_id'];
                    $data['is_del'] = 1;
                    $data['create_time'] = time();

                    $this->db->trans_begin();
                    $this->db->insert("bbs_wenda_care", $data);
                    $query1 = $this->db->affected_rows();
                    $query2 = $this->db->query("update tan_bbs_wenda set focusnum = focusnum + 1 where id = " . $wenda_id);
                    $query3 = $this->db->query("update tan_bbs_count set follow_question_count = follow_question_count + 1 where user_id = " . $this->user_id);
                    if ($query1 && $query2 && $query3) {
                        $this->db->trans_commit();
                        //发送消息通知
                        $this->insert_notice(array("user_id" => $this->user_id, "recieve_id" => $wenda['questioner_id'], "operator_id" => $wenda_id, "event_type" => "event_care_answer", "type" => "wenda", "is_show" => 1));
//                        //更新个人动态
//                        $this->insert_behavior(array("user_id"=>$this->bbs_userinfo['user_id'],"operator_id"=>$author_id,"event_type"=>"event_focus_author","is_show"=>1));

                        $mess['reqStatus'] = true;
                        $mess['count'] = $wenda['focusnum'] + 1;
                        echo JSON($mess);
                        exit;
                    } else {
                        $this->db->trans_rollback();
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "操作失败，请稍后重试";
                        echo JSON($mess);
                        exit;
                    }
                }
            } else {//取消
                $status = $this->db->select("*")->from("bbs_wenda_care")->where(array("user_id" => $this->user_id, "wenda_id" => $wenda_id, "is_del" => 1))->order_by("id desc")->get()->row_array();
                if (!$status) {
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "非法操作";
                    echo JSON($mess);
                    exit;
                }
                $this->db->trans_begin();
                $query1 = $this->db->query("update tan_bbs_wenda_care set is_del = 0 where id = " . $status['id']);
                $query2 = $this->db->query("update tan_bbs_wenda set focusnum = focusnum - 1 where id = " . $wenda_id);
                $query3 = $this->db->query("update tan_bbs_count set follow_question_count = follow_question_count - 1 where user_id = " . $this->user_id);

                if ($query1 && $query2 && $query3) {
                    $this->db->trans_commit();
                    $mess['reqStatus'] = true;
                    $mess['count'] = $wenda['focusnum'] - 1;
                    echo JSON($mess);
                    exit;
                } else {
                    $this->db->trans_rollback();
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "操作失败，请稍后重试";
                    echo JSON($mess);
                    exit;
                }
            }
        }
    }

    //获取问答答案
    function ajax_fetch_wenda_answer() {
        if ($_POST) {
            $wenda_id = isset($_POST['wendaId']) ? trim($_POST['wendaId']) : 0;
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $wenda_id = decrypt_wenda_id($wenda_id);
            $wenda = $this->db->select("id,questioner_id,answer_id,title,answernum")->from("bbs_wenda")->where(array("id" => $wenda_id))->order_by("id")->get()->row_array();
            $records_per_page = 15;

            $select_str = "a.id,a.user_id,a.content,a.likes,a.commentnum,a.is_answer,a.create_time,u.nickname,u.head_img";
            $list = $this->db->query("select $select_str from tan_bbs_wenda_answer a left join tan_users_info u on u.user_id = a.user_id where a.wenda_id = $wenda_id and a.is_show = 1 order by a.is_answer desc,a.likes desc,a.id desc limit " . ($pageIndex * $records_per_page) . ",$records_per_page")->result_array();
            $html = "";
            foreach ($list as $key => $val) {

                $is_like = $this->user_id ? ($this->db->select("*")->from("bbs_wenda_answer_like")->where(array("user_id" => $this->user_id, "answer_id" => $val['id'], "is_del" => 1))->order_by("id")->get()->num_rows() ? 1 : 0) : 0;

                //匹配回答内容里所有图片
                preg_match_all("/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png|\.bmp|\.jpeg]))[\'|\"].*?[\/]?>/i", $val['content'], $matches); //带引号 
                $new_arr = array_unique($matches[0]); //去除数组中重复的值 
                $val['head_img'] = strstr($val['head_img'], "http") ? $val['head_img'] : $this->img_host . $val['head_img'];
                $answet_id = encrypt_answer_id($val['id']);
                $html .= "<li class='border-bottom-lg' id='answer-$answet_id' data-aid='$answet_id'>";
                $html .= "    <div class='plr15 ptb10 answer disblock'>";
                $html .= "        <div class='user-head f-cb mb10'>";
                $html .= "            <img src='$val[head_img]' class='head fl'/>";
                $html .= "            <span class='name fl ml5'>$val[nickname]</span>";
                $html .= "            <img src='/static/weixin/img/vip/vip1.png' class='badge fl ml5'/>";
                if ($val['is_answer']) {
                    $html .= "<button class='adopt fr iconfont active'>&#xe697; <i>最佳答案</i></button>";
                } else {
                    if (!$wenda['answer_id']) {
                        if ($this->user_id == $wenda['questioner_id']) {
                            $html .= "<button class='adopt fr iconfont _answer'>&#xe697; <i>采纳为答案</i></button>";
                        }
                    }
                }
                $html .= "        </div>";
                $html .= "        <a href='" . site_url("wenda/" . encrypt_wenda_id($wenda_id) . "/answer/" . $answet_id) . "' class='disblock'>";
                $answer_content = strip_tags($val['content']);
                $answer_content = mb_substr($answer_content, 0, 90, "utf8");
                $html .= "            <p class='text'>$answer_content" . ( mb_strlen(strip_tags($answer_content), "utf8") > 60 ? "..." : "") . "</p>" . ( mb_strlen(strip_tags($answer_content), "utf8") > 60 ? "<span class='all col-red'>查看更多>><span>" : "");
                if ($new_arr) {//显示图片
                    $html .= "            <ul class='proportion-img ptb5'>";
                    foreach ($new_arr as $k => $img) {
                        if (($k + 1) <= 3) {
                            $html .= "<li>$img</li>";
                        }
                    }
                    $html .= "            </ul>";
                }
                $html .= "         </a>";
                $html .= "            <div class='num f-cb mt10'>";
                $html .= "                <font class='iconfont " . ($is_like ? "col-redf941" : "col-grey999") . " fct-list-like' data-val='$is_like' data-aid='$answet_id' data-uid='" . encrypt_user_id($val['user_id']) . "'>&#xe615;<i>$val[likes]</i></font>";
                $html .= "                <font class='iconfont col-grey999 fr'>&#xe675;<i>$val[commentnum]</i></font>";
                $html .= "            </div>";
                $html .= "    </div>";
                $html .= "</li>";
            }
            echo $html;
            die;
        }
    }

    //问答设置最佳答案
    function ajax_wd_best() {
        $this->is_login();
        if ($_POST) {
            $wenda_id = isset($_POST['wendaId']) ? trim($_POST['wendaId']) : 0;
            $answer_id = isset($_POST['answerId']) ? trim($_POST['answerId']) : 0;
            $uuid = isset($_POST['uuid']) ? trim($_POST['uuid']) : 0;
            $wenda_id = decrypt_wenda_id($wenda_id);
            $answer_id = decrypt_answer_id($answer_id);
            $uuid = decrypt_user_id($uuid);

            if ($this->user_id != $uuid) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);
                exit;
            }

            $wenda = $this->db->select("id,questioner_id,answer_id")->from("bbs_wenda")->where(array('id' => $wenda_id))->order_by("id desc")->get()->row_array();
            if ($wenda['answer_id']) {//问题已经有答案了
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);
                exit;
            }

            if ($wenda['questioner_id'] != $uuid) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);
                exit;
            }

            $answer = $this->db->select("id,user_id")->from("bbs_wenda_answer")->where(array('id' => $answer_id))->order_by("id desc")->get()->row_array();
            if (!$answer) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "此回答不存在或已被删除";
                echo JSON($mess);
                exit;
            }
            $this->db->trans_begin();
            $query1 = $this->db->query("update tan_bbs_wenda set answer_id = $answer[id],answer_uid = $answer[user_id] where id = $wenda_id");
            $query2 = $this->db->query("update tan_bbs_wenda_answer set is_answer = 1 where id = $answer_id");
            $query3 = $this->db->query("update tan_bbs_count set answer_best_count = answer_best_count + 1 where user_id = $answer[user_id]");

            if ($query1 && $query2 && $query3) {
                $this->db->trans_commit();


                //发送通知
                $this->insert_notice(array("user_id" => $this->user_id, "recieve_id" => $answer['user_id'], "operator_id" => $answer_id, "event_type" => "event_best_answer", "type" => "wenda", "is_show" => 1));
                $mess['reqStatus'] = true;
                $mess['errorMsg'] = "已采纳为最佳答案！";
                echo JSON($mess);
                exit;
            } else {
                $this->db->trans_rollback();
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作失败，请稍后重试";
                echo JSON($mess);
                exit;
            }
        }
    }

    //加载问答评论
    function ajax_fetch_reply() {
        if ($_POST) {
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $answerId = isset($_REQUEST['answerId']) ? trim($_REQUEST['answerId']) : 0;
            $answerId = decrypt_answer_id($answerId);
            $records_per_page = 15;
            $list = $this->db->select("r.*,u1.head_img,u1.nickname nickname1,u2.nickname nickname2")->from("bbs_wenda_reply r")->join("users_info u1", "u1.user_id=r.user_id", "left")->join("users_info u2", "u2.user_id=r.reply_uid", "left")->where(array("r.answer_id" => $answerId, "r.is_show" => 1))->order_by("id asc")->limit($records_per_page, ($pageIndex) * $records_per_page)->get()->result_array();
            $html = "";
            foreach ($list as $key => $val) {
                $reply_id = encrypt_answer_reply_id($val['id']);
                $time_str = $this->set_time_two($val['create_time']);
                $is_self = $this->user_id == $val['user_id'] ? 1 : 0;
                $reply_btn_str = "<a href='javascript:;' class='publicText _reply' data-rid='$reply_id' data-rname='$val[nickname1]'>回复</a>";

                $lengther = mb_strlen($val['content'], "utf8");
                $show_more = $lengther > 70 ? "<a href='javascript:;' class='all col-red'>展开↓</a>" : "";

                if ($val['reply_uid']) {
                    $reply_str = '<p class="text">回复<a href="' . site_url("u/" . encrypt_user_id($val['reply_uid'])) . '" class="col-red">' . $val['nickname2'] . '</a>：' . $val['content'] . '</p>' . $show_more;
                } else {
                    $reply_str = '<p class="text">' . $val['content'] . '</p>' . $show_more;
                }
                $val['head_img'] = strstr($val['head_img'], "http") ? $val['head_img'] : $this->img_host . $val['head_img'];
                $html .= "<li class='f-cb ptb10 border-bottom-sm' id='answer-reply-$reply_id' data-rid='$reply_id'>
                            <div class='f-cb plr15 user-head'>
                                <a href='" . site_url("u/" . encrypt_user_id($val['user_id'])) . "' class='name'>
                                    <img src='$val[head_img]' class='head fl'/>
                                    <span class='name fl ml5'>$val[nickname1]</span>
                                    <img src='/static/weixin/img/vip/vip2.png' class='badge fl ml5'/>
                                </a>
                                <!--菜单-->
                                <div class='comments-menu'>
                                    <div class='menuToggle icon-menu iconfont fr'>&#xe6a0;</div>
                                    <!--隐藏菜单-->
                                    <div class='menu-toggle'>
                                        <b></b>
                                        " . ($is_self ? '<a href="javascript:;" class="delete-jq" onclick="delete_reply_act({reply_id:' . encrypt_answer_reply_id($val['id']) . ',obj:this});">删除</a>' : "") . "
                                        " . $reply_btn_str . "
                                        <a href='javascript:;' class='publicReport _report' data-rel='http://www.tan66.com/wenda/" . encrypt_wenda_id($val['wenda_id']) . "/answer/" . encrypt_answer_id($val['answer_id']) . "/reply-" . $reply_id . ".html'>举报</a>
                                    </div>
                                </div>
                            </div>
                            <div class='disblock plr15 user-head'>
                                <div class='text-toggle mtb5'>
                                    $reply_str
                                </div>
                                <p class='time fr'>$time_str</p>
                            </div>
                        </li>";
            }
        }
        echo $html;
        die;
    }

    //修改或增加问题回答
    function ajax_modify_answer() {
        $this->is_login();
        if ($_POST) {
            $wendaId = isset($_POST['wendaId']) ? trim($_POST['wendaId']) : 0; //问答id
            $answerContent = isset($_POST['answerContent']) ? trim($_POST['answerContent']) : ""; //回答内容
            $answerId = isset($_POST['answerId']) ? trim($_POST['answerId']) : 0; //回答id
            $type = isset($_POST['type']) ? trim($_POST['type']) : 0; //回答id
            if (!$type) {//修改答案
                if ($answerId) {
                    $answerId = decrypt_answer_id($answerId);
                    $answer = $this->db->select("*")->from("bbs_wenda_answer")->where(array("id" => $answerId, "user_id" => $this->user_id))->order_by("id desc")->get()->row_array();
                    if (!$answer) {
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "非法操作";
                        echo JSON($mess);
                        exit;
                    }
                }
            }

            if ($answerContent == "") {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "提交的回答不能为空哦";
                echo JSON($mess);
                exit;
            }
            $wendaId = decrypt_wenda_id($wendaId);
            $wenda = $this->db->select("id,questioner_id,is_email_noitce,answer_id")->from("bbs_wenda")->where(array("id" => $wendaId))->order_by("id desc")->get()->row_array();
            if (!$wenda) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);
                exit;
            }

            if ($wenda['questioner_id'] == $this->user_id) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "不能自己给自己作答哦";
                echo JSON($mess);
                exit;
            }

            $allergicWord = file_get_contents("http://static.tan66.com/upfiles/files/badwords.txt");
            $allergicWord = str_replace(array("\r\n", "\r", "\n"), '', $allergicWord);
            $allergicWord = explode('|', $allergicWord);
            $info = 0;
            for ($i = 0; $i < count($allergicWord); $i++) {
                $check = substr_count($answerContent, $allergicWord[$i]);
                if ($check > 0) {
                    $info = $check;
                    break;
                }
            }
            if ($info > 0) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "回答内容里面有非法或敏感内容，请修正";
                echo JSON($mess);
                exit;
            }

            preg_match_all("/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png|\.bmp|\.jpeg]))[\'|\"].*?[\/]?>/i", $answerContent, $matches);
            $thumb = $matches[1][0] ? $matches[1][0] : "";
            if ($thumb) {
                $result = $this->crypt->POST_Api("http://static.tan66.com/mimage/resize/150/100", array("file" => $thumb));
                $result = json_decode($result, true);
                $thumb = $result['filename'];
            } else {
                $thumb = "";
            }

            $data = array();
            $data['user_id'] = $this->user_id;
            $data['wenda_id'] = $wendaId;
            $data['wenda_uid'] = $wenda['questioner_id'];
            $data['thumb'] = $thumb;
            $data['content'] = strip_tags($answerContent, "<br><img><p><div><a>");

            if (!$type) {//修改回答
                $this->db->trans_begin();
                $query = $this->db->where(array("id" => $answerId))->update("bbs_wenda_answer", $data);
                if ($query) {
                    $this->db->trans_commit();
                    $mess['reqStatus'] = true;
                    echo JSON($mess);
                    exit;
                } else {
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "操作失败，请稍后重试";
                    echo JSON($mess);
                    exit;
                }
            } else {//增加回答]
                $data['create_time'] = time();

                $this->db->trans_begin();
                $this->db->insert("bbs_wenda_answer", $data);
                $insert_id = $this->db->insert_id();
                $query1 = $this->db->query("update tan_bbs_wenda set answernum = answernum + 1 where id = " . $wendaId);
                $query2 = $this->db->query("update tan_bbs_count set answer_count = answer_count + 1 where user_id = " . $this->user_id);
                if ($insert_id && $query1 && $query2) {
                    $this->db->trans_commit();
                    //发送通知
                    //1、向问题发表者发送新答案通知
                    $this->insert_notice(array("user_id" => $this->user_id, "recieve_id" => $wenda['questioner_id'], "operator_id" => $insert_id, "event_type" => "event_comment_wenda", "is_show" => 1, "type" => "wenda"));
                    //2、向关注此问题的所有人发送新答案通知
                    if (!$wenda['answer_id']) {//问题还未被采纳
                        $datas = array();
                        //获取关注问答的人
                        $cares = $this->db->query("SELECT user_id FROM `tan_bbs_wenda_care` where wenda_id = $wendaId and is_del = 1 order by id desc")->result_array();
                        if ($cares) {
                            foreach ($cares as $val) {
                                if ($val['user_id'] == $this->user_id) {
                                    continue;
                                }
                                $data = array();
                                $data['user_id'] = 0;
                                $data['recieve_id'] = $val['user_id'];
                                $data['operator_id'] = $insert_id;
                                $data['event_type'] = "event_comment_wenda_care";
                                $data['type'] = "wenda";
                                $data['is_show'] = 0;
                                $data['create_time'] = time();
                                $datas[] = $data;
                            }
                            $this->db->insert_batch("bbs_notice", $datas);
                        }
                    }
                    $mess['reqStatus'] = true;
                    $mess['url'] = site_url("wenda/" . encrypt_wenda_id($wendaId) . "/answer/" . encrypt_answer_id($insert_id));
                    echo JSON($mess);
                    exit;
                } else {
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "操作失败，请稍后重试";
                    echo JSON($mess);
                    exit;
                }
            }
        }
    }

    //增加问答评论
    function ajax_add_reply() {
        $this->is_login();
        if ($_POST) {
            $answerId = isset($_POST['answerId']) ? trim($_POST['answerId']) : 0; //回答id
            $replyTxt = isset($_POST['replyTxt']) ? trim($_POST['replyTxt']) : ""; //评论内容
            $replyId = isset($_POST['replyId']) ? trim($_POST['replyId']) : 0; //评论id
            $answerId = decrypt_answer_id($answerId);
            $replyId = $replyId ? decrypt_answer_reply_id($replyId) : 0;

            $answer = $this->db->select("*")->from("bbs_wenda_answer")->where(array("id" => $answerId, "is_show" => 1))->order_by("id asc")->get()->row_array();
            if (!$answer) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);
                exit;
            }

            if ($replyId) {
                $reply = $this->db->select("*")->from("bbs_wenda_reply")->where(array("id" => $replyId, "answer_id" => $answerId, "is_show" => 1))->order_by("id asc")->get()->row_array();
                if (!$reply) {
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "非法操作";
                    echo JSON($mess);
                    exit;
                }
            }
            $allergicWord = file_get_contents("http://static.tan66.com/upfiles/files/badwords.txt");
            $allergicWord = str_replace(array("\r\n", "\r", "\n", " "), '', $allergicWord);
            $allergicWord = explode('|', $allergicWord);
            $info = 0;
            for ($i = 0; $i < count($allergicWord); $i++) {
                $check = substr_count($replyTxt, $allergicWord[$i]);
                if ($check > 0) {
                    $info = $check;
                    break;
                }
            }
            if ($info > 0) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "检查您的评论内容里面有非法或敏感内容，请修正";
                echo JSON($mess);
                exit;
            }

            $data = array();
            $data['user_id'] = $this->user_id;
            $data['answer_id'] = $answerId;
            $data['answer_uid'] = $answer['user_id'];
            $data['wenda_id'] = $answer['wenda_id'];
            $data['wenda_uid'] = $answer['wenda_uid'];
            $data['content'] = $replyTxt;
            $data['create_time'] = time();
            $data['reply_id'] = $reply ? $reply['id'] : 0;
            $data['reply_uid'] = $reply ? $reply['user_id'] : 0;
            $data['is_show'] = 1;

            $this->db->trans_begin();
            $this->db->insert("bbs_wenda_reply", $data);
            $insert_id = $this->db->insert_id();
            $query1 = $this->db->query("update tan_bbs_wenda_answer set commentnum = commentnum + 1 where id = " . $answerId);
            if ($insert_id && $query1) {
                $this->db->trans_commit();

                //发送消息
                if ($reply) {
                    if ($reply['user_id'] != $this->user_id) {
                        $this->insert_notice(array("user_id" => $this->user_id, "recieve_id" => $reply['user_id'], "operator_id" => $insert_id, "event_type" => "event_reply_wenda", "is_show" => 1, "type" => "wenda"));
                    }
                } else {
                    if ($answer['user_id'] != $this->user_id) {
                        $this->insert_notice(array("user_id" => $this->user_id, "recieve_id" => $answer['user_id'], "operator_id" => $insert_id, "event_type" => "event_reply_wenda", "is_show" => 1, "type" => "wenda"));
                    }
                }
                //新评论
                $reply = $this->db->select("r.*,u1.head_img,u1.nickname nickname1,u2.nickname nickname2")->from("bbs_wenda_reply r")->join("users_info u1", "u1.user_id=r.user_id", "left")->join("users_info u2", "u2.user_id=r.reply_uid", "left")->where(array("r.id" => $insert_id, "r.is_show" => 1))->order_by("id asc")->limit(1)->get()->row_array();
                $reply_id = encrypt_answer_reply_id($insert_id);

                $lengther = mb_strlen($reply['content'], "utf8");
                $show_more = $lengther > 70 ? "<a href='javascript:;' class='all col-red'>展开↓</a>" : "";

                $reply_btn_str = "<a href='javascript:;' class='publicText _reply' data-rid='$reply_id' data-rname='$reply[nickname1]'>回复</a>";
                if ($reply['reply_uid']) {
                    $reply_str = '<p class="text">回复<a href="' . site_url("u/" . encrypt_user_id($reply['reply_uid'])) . '" class="col-red">' . $reply['nickname2'] . '</a>：' . $reply['content'] . '</p>' . $show_more;
                } else {
                    $reply_str = '<p class="text">' . $reply['content'] . '</p>' . $show_more;
                }
                $time_str = $this->set_time_two($reply['create_time']);

                $reply['head_img'] = strstr($reply['head_img'], "http") ? $reply['head_img'] : $this->img_host . $reply['head_img'];
                $html = "<li class='f-cb ptb10 border-bottom-lg' id='answer-reply-$reply_id' data-rid='$reply_id'>
                            <div class='f-cb plr15 user-head'>
                                <a href='" . site_url("u/" . encrypt_user_id($this->user_id)) . "' class='name'>
                                    <img src='$reply[head_img]' class='head fl'/>
                                    <span class='name fl ml5'>$reply[nickname1]</span>
                                    <img src='/static/weixin/img/vip/vip2.png' class='badge fl ml5'/>
                                </a>
                                <!--菜单-->
                                <div class='comments-menu'>
                                    <div class='menuToggle icon-menu iconfont fr'>&#xe6a0;</div>
                                    <!--隐藏菜单-->
                                    <div class='menu-toggle'>
                                        <b></b>
                                        <!--<a href='javascript:;' class='delete-jq' onclick='delete_reply_act({reply_id:$reply_id,obj:this});'>删除</a>-->
                                        " . $reply_btn_str . "
                                        <a href='javascript:;' class='publicReport _report' data-rel='http://www.tan66.com/wenda/" . encrypt_wenda_id($reply['wenda_id']) . "/answer/" . encrypt_answer_id($reply['answer_id']) . "/reply-" . $reply_id . ".html'>举报</a>
                                    </div>
                                </div>
                            </div>
                            <div class='disblock plr15 user-head'>
                                <div class='text-toggle mtb5'>
                                    $reply_str
                                </div>
                                <p class='time fr'>$time_str</p>
                            </div>
                        </li>";


                $mess['reqStatus'] = true;
                $mess['htmlData'] = $html;
                $mess['replyNum'] = $answer['commentnum'] + 1;
                ;
                echo json_encode($mess, JSON_HEX_TAG);
                exit;
            } else {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作失败，请稍后重试";
                echo JSON($mess);
                exit;
            }
        }
    }

    //增加问答阅读数
    function ajax_wd_read_up() {
        if ($_GET) {
            $wenda_id = isset($_GET['wenda_id']) ? trim($_GET['wenda_id']) : 0;
            $uuid = isset($_GET['uuid']) ? trim($_GET['uuid']) : 0;
            $wenda_id = decrypt_wenda_id($wenda_id);
            $uuid = decrypt_user_id($uuid);
            if ($uuid == $this->user_id) {
                $mess['reqStatus'] = false;
                echo JSON($mess);
                exit;
            }
            $wenda = $this->db->select("id,title,questioner_id,readnum")->from("bbs_wenda")->where(array("id" => $wenda_id))->get()->row_array();
            if (!$wenda) {
                $mess['reqStatus'] = false;
                echo JSON($mess);
                exit;
            }
            if ($wenda['questioner_id'] == $this->user_id) {
                $mess['reqStatus'] = false;
                echo JSON($mess);
                exit;
            }
            $this->db->trans_begin();
            $query = $this->db->query("update tan_bbs_wenda set readnum = readnum + 1 where id = " . $wenda_id);
            if ($query) {
                $this->db->trans_commit();

                $mess['reqStatus'] = true;
                $mess['readNum'] = $wenda['readnum'] + 1;
                echo JSON($mess);
                exit;
            } else {
                $this->db->trans_rollback();
                $mess['reqStatus'] = false;
                echo JSON($mess);
                exit;
            }
        }
    }

    //问答点赞处理
    function ajax_wd_up() {
        $this->is_login();
        if ($_POST) {
            $answerId = isset($_POST['answerId']) ? trim($_POST['answerId']) : 0;
            $auid = isset($_POST['answerUid']) ? trim($_POST['answerUid']) : 0;
            $value = isset($_POST['value']) ? trim($_POST['value']) : 0;
            $answerId = decrypt_answer_id($answerId);
            $auid = decrypt_user_id($auid);

            $answer = $this->db->select("*")->from("bbs_wenda_answer")->where(array("id" => $answerId, "is_show" => 1))->order_by("id asc")->get()->row_array();
            if (!$answer) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);
                exit;
            }
            if ($answer['user_id'] != $auid) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);
                exit;
            }

            if ($answer['user_id'] == $this->user_id) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "不能给自己点赞哦";
                echo JSON($mess);
                exit;
            }

            if ($value) {//点赞
                $status = $this->db->select("*")->from("bbs_wenda_answer_like")->where(array("user_id" => $this->user_id, "answer_id" => $answerId, "is_del" => 0))->order_by("id desc")->get()->row_array();
                if ($status) {
                    $this->db->trans_begin();
                    $query1 = $this->db->query("update tan_bbs_wenda_answer_like set is_del = 1 where id = " . $status['id']);
                    $query2 = $this->db->query("update tan_bbs_wenda set likes = likes + 1 where id = " . $answer['wenda_id']);
                    $query3 = $this->db->query("update tan_bbs_wenda_answer set likes = likes + 1 where id = " . $answer['id']);

                    if ($query1 && $query2 && $query3) {
                        $this->db->trans_commit();
                        $mess['reqStatus'] = true;
                        $mess['count'] = $answer['likes'] + 1;

                        echo JSON($mess);
                        exit;
                    } else {
                        $this->db->trans_rollback();
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "操作失败，请稍后重试";
                        echo JSON($mess);
                        exit;
                    }
                } else {
                    $data = array();
                    $data['user_id'] = $this->user_id;
                    $data['answer_id'] = $answerId;
                    $data['is_del'] = 1;
                    $data['create_time'] = time();

                    $this->db->trans_begin();
                    $this->db->insert("bbs_wenda_answer_like", $data);
                    $query1 = $this->db->affected_rows();
                    $query2 = $this->db->query("update tan_bbs_wenda set likes = likes + 1 where id = " . $answer['wenda_id']);
                    $query3 = $this->db->query("update tan_bbs_wenda_answer set likes = likes + 1 where id = " . $answerId);
                    if ($query1 && $query2 && $query3) {
                        $this->db->trans_commit();
                        //发送消息通知
                        $this->insert_notice(array("user_id" => $this->user_id, "recieve_id" => $answer['user_id'], "operator_id" => $answer['id'], "event_type" => "event_like_answer", "type" => "wenda", "is_show" => 1));
//                        //更新个人动态
//                        $this->insert_behavior(array("user_id"=>$this->bbs_userinfo['user_id'],"operator_id"=>$author_id,"event_type"=>"event_focus_author","is_show"=>1));

                        $mess['reqStatus'] = true;
                        $mess['count'] = $answer['likes'] + 1;
                        echo JSON($mess);
                        exit;
                    } else {
                        $this->db->trans_rollback();
                        $mess['reqStatus'] = false;
                        $mess['errorMsg'] = "操作失败，请稍后重试";
                        echo JSON($mess);
                        exit;
                    }
                }
            } else {//取消
                $status = $this->db->select("*")->from("bbs_wenda_answer_like")->where(array("user_id" => $this->user_id, "answer_id" => $answerId, "is_del" => 1))->order_by("id desc")->get()->row_array();
                if (!$status) {
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "非法操作";
                    echo JSON($mess);
                    exit;
                }
                $this->db->trans_begin();
                $query1 = $this->db->query("update tan_bbs_wenda_answer_like set is_del = 0 where id = " . $status['id']);
                $query2 = $this->db->query("update tan_bbs_wenda set likes = likes - 1 where id = " . $answer['wenda_id']);
                $query3 = $this->db->query("update tan_bbs_wenda_answer set likes = likes - 1 where id = " . $answer['id']);

                if ($query1 && $query2 && $query3) {
                    $this->db->trans_commit();
                    $mess['reqStatus'] = true;
                    $mess['count'] = $answer['likes'] - 1;
                    echo JSON($mess);
                    exit;
                } else {
                    $this->db->trans_rollback();
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "操作失败，请稍后重试";
                    echo JSON($mess);
                    exit;
                }
            }
        }
    }

    //举报
    function ajax_report() {
        $this->is_login();
        if ($_POST) {
            $type = isset($_POST['type']) ? trim($_POST['type']) : "其他";
            $content = isset($_POST['des']) ? trim($_POST['des']) : "";
            $rel = isset($_POST['rel']) ? trim($_POST['rel']) : "";

            $data = array();
            $data['target_type'] = $type;
            $data['target_content'] = $content;
            $data['target_rel'] = $rel;
            $data['create_time'] = time();
            $this->db->insert("bbs_report_list", $data);

            $mess['reqStatus'] = true;
            $mess['errorMsg'] = "举报成功！";
            echo JSON($mess);
            exit;
        }
    }

    //溜珠明细
    function get_zhu_detail() {
        if ($_POST) {
            $this->is_login();
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $records_per_page = 10;
            $dataOffset = 10 + $pageIndex * $records_per_page;
            $list = $this->db->query("select * from tan_bbs_zhu_detail where user_id = " . $this->user_id . " order by id desc limit $dataOffset,$records_per_page")->result_array();
            $html = "";
            foreach ($list as $key => $val) {
                $html .= "<tr><td>$val[type]</td><td>" . ($val['style'] == 1 ? "-" : "+") . "$val[num]</td><td>" . date("Y-m-d H:s", $val['create_time']) . "</td></tr>";
            }
            echo $html;
            die;
        }
    }

    function ajax_modify_baseinfo() {
        $this->is_login();
        if ($_POST) {
            $set_type = isset($_REQUEST['setType']) ? trim($_REQUEST['setType']) : "";
            $set_value = isset($_REQUEST['setValue']) ? trim($_REQUEST['setValue']) : "";
            $update_data = array();
            $table_name = "";
            if (!$set_type) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法参数";
                echo JSON($mess);
                exit;
            }
            if ($set_type == "nickname") {//修改昵称
                if (!$set_value) {
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "昵称不能为空";
                    echo JSON($mess);
                    exit;
                }
                $table_name = "users_info";
                $update_data['nickname'] = $set_value;
                $this->users_model->users_alter($this->user_id, "isupdate");
            } elseif ($set_type == "signature") {//修改个性签名
                $table_name = "users_info";
                $update_data['signature'] = $set_value;
            } elseif ($set_type == "head_img") {//修改头像
                $table_name = "users_info";
                $update_data['head_img'] = $set_value;
            } elseif ($set_type == "sex") {//修改性别
                $set_value = $set_value ? $set_value : 1;
                $table_name = "users_info";
                $update_data['sex'] = $set_value;
            } elseif ($set_type == "loginpass") {//修改登录密码
                $oldPass = isset($_POST['oldPass']) ? trim($_POST['oldPass']) : "";
                $newPass = isset($_POST['newPass']) ? trim($_POST['newPass']) : "";
                if (!$oldPass) {
                    $mess['errorMsg'] = "请输入原登录密码";
                    $mess['reqStatus'] = false;
                    echo JSON($mess);
                    exit;
                }
                $uinfo = $this->users_model->get_user_by_uid($this->user_id);
                $is_pass = $uinfo['password'] == md5(md5($oldPass) . $uinfo['salt']);
                //验证密码
                if (!$is_pass) {
                    $mess['errorMsg'] = '原登录密码错误';
                    $mess['reqStatus'] = false;
                    echo JSON($mess);
                    exit;
                }
                if (!$newPass) {
                    $mess['errorMsg'] = "请输入新登录密码";
                    $mess['reqStatus'] = false;
                    echo JSON($mess);
                    exit;
                }
                $newLoginPass = md5(md5($newPass) . $uinfo['salt']);

                $table_name = "users";
                $update_data['password'] = $newLoginPass;
            } elseif ($set_type == "paypass") {//修改交易密码
                $new_paypass = isset($_POST['newPaypass']) ? trim($_POST['newPaypass']) : "";
                $ucode = isset($_POST['uCode']) ? trim($_POST['uCode']) : "";
                if (!$new_paypass) {
                    $mess['errorMsg'] = '交易密码不能为空';
                    $mess['reqStatus'] = false;
                    echo JSON($mess);
                    exit;
                }
                if (!$ucode) {
                    $mess['errorMsg'] = '验证码不能为空';
                    $mess['reqStatus'] = false;
                    echo JSON($mess);
                    exit;
                }
                if ($ucode != $this->session->userdata('paypass_code')) {
                    $mess['errorMsg'] = '验证码输入有误';
                    $mess['reqStatus'] = false;
                    echo JSON($mess);
                    exit;
                }
                $uinfo = $this->users_model->get_user_by_uid($this->user_id);
                $md5paypass = md5(md5($new_paypass) . $uinfo['salt']);

                $table_name = "users";
                $update_data['paypassword'] = $md5paypass;
            } else {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法参数";
                echo JSON($mess);
                exit;
            }
            $result = $this->db->where("user_id", $this->user_id)->update($table_name, $update_data);
            if ($result) {
                if ($set_type == "loginpass") {

                    $this->users_model->users_alter($this->user_id, "isupdatepw");

                    $this->session->sess_destroy();
                    $mess['url'] = site_url("account/login");
                } else {
                    $this->users_model->users_alter($this->user_id, "isupdate");
                }
                $mess['reqStatus'] = true;
                $mess['errorMsg'] = "保存成功";
                echo JSON($mess);
                exit;
            } else {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "保存失败";
                echo JSON($mess);
                exit;
            }
        }
    }

    //解除第三方登录绑定
    function cancel_bind_login() {
        $this->is_login();
        if ($_POST) {
            $bind_type = isset($_POST['bindType']) ? trim($_POST['bindType']) : "";
            if ($bind_type == "qq") {
                $this->users_model->del_qq_bind(intval($this->user_id));
            } elseif ($bind_type == "weibo") {
                $this->users_model->del_weibo_bind(intval($this->user_id));
            } elseif ($bind_type == "weixin") {
                $this->users_model->del_weixin_bind(intval($this->user_id));
            }
            $result = $this->db->affected_rows();
            if ($result) {
                $mess['reqStatus'] = true;
                echo JSON($mess);
                exit;
            } else {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作有误";
                echo JSON($mess);
                exit;
            }
        }
    }

    //判断是否登录
    private function is_login() {
        if ($_POST && !$this->userinfo) {
            $mess['reqStatus'] = false;
            $mess['errorCode'] = 1001;
            $mess['errorMsg'] = "请先登录，再操作哦";
            echo JSON($mess);
            exit;
        }
        if ($_GET && !$this->userinfo) {
            redirect("/");
        }
    }

    //视频点赞or点差
    function video_like_num_add() {
        $this->is_login();
        if ($_POST) {
            $video_id = isset($_POST['video_id']) ? trim($_POST['video_id']) : 0;
            $status = trim($_POST['status']);
            $type = isset($_POST['type']) ? trim($_POST['type']) : "like";
            $video_id = decrypt_video_id($video_id);
            $video = $this->db->select("id,title,likes,hates")->from("video")->where(array("id" => $video_id, 'status' => 1))->order_by("id desc")->get()->row_array();
            if (!$video) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "视频资源不存在或已被删除";
                echo JSON($mess);
                exit;
            }
            $user_id = $this->user_id;

            $data = array();
            $data['video_id'] = $video['id'];
            $data['user_id'] = $user_id;
            $data['create_time'] = time();
            if ($type == "hate") {//讨厌操作
                $data['status'] = 0;
                $this->video_model->insert_video_hates($data);
                $mess['num'] = $video['hates'] + 1;
            } else {//喜欢操作
                $data['status'] = 1;
                $this->video_model->insert_video_like($data);
                $mess['num'] = $video['likes'] + 1;
            }

            $mess['reqStatus'] = true;
            $mess['type'] = $type;
            echo JSON($mess);
            exit;
        }
    }

    //增加视频阅读数
    function video_read_num_add() {
        if ($_GET) {
            $video_id = isset($_GET['vid']) ? trim($_GET['vid']) : 0;
            $video_id = decrypt_video_id($video_id);
            $video = $this->db->select("id,readnum")->from("video")->where(array("id" => $video_id))->get()->row_array();
            if (!$video) {//视频不存在
                $mess['reqStatus'] = false;
                echo JSON($mess);
                exit;
            }
            $this->db->trans_begin();
            $query = $this->db->query("update tan_video set readnum = readnum + 1 where id = " . $video_id);
            if ($query) {
                $this->db->trans_commit();

                $mess['reqStatus'] = true;
                $mess['readNum'] = $video['readnum'] + 1;
                echo JSON($mess);
                exit;
            } else {
                $this->db->trans_rollback();
                $mess['reqStatus'] = false;
                echo JSON($mess);
                exit;
            }
        }
    }

    //显示视频评论信息
    function get_video_comments_json() {
        if ($_POST) {
            $video_id = isset($_REQUEST['vid']) ? trim($_REQUEST['vid']) : 0; //视频id
            $pageIndex = isset($_REQUEST['currentPage']) ? trim($_REQUEST['currentPage']) : 0; //显示当前页
            $comment_id = isset($_REQUEST['comment_id']) ? trim($_REQUEST['comment_id']) : 0; //评论id
            // $goto = isset($_REQUEST['goto']) ? trim($_REQUEST['goto']) : false;//是否跳转到知道评论
            $video_id = decrypt_video_id($video_id);
            $comment_id = $comment_id ? decrypt_comment_id($comment_id) : 0;
            //每页显示数量
            $records_per_page = 19;
            // $is_goto = false;
            //获取视频
            $video = $this->db->select("id,authorid,status,salt")->from("video")->where(array("id" => $video_id))->order_by("create_time desc")->get()->row_array();
            if (!$video) {
                echo "";
                die;
            }
            $comment = $this->db->select("*")->from("video_comment")->where(array("id" => $comment_id, "is_show" => 1))->order_by("create_time desc")->get()->row_array();
            if ($comment) {
                $where = array();
                $where['video_id'] = $comment['video_id'];
                $where['is_show'] = 1;
                $where['id <='] = $comment['id'];
                //获取评论总条数
                $comment_totalCount = $this->db->select("*")->from("video_comment")->where($where)->order_by("id asc")->get()->num_rows();
                //计算当前评论所处的哪一页
                $pageIndex = intval(($comment_totalCount / $records_per_page)) == 0 ? intval(($comment_totalCount / $records_per_page)) : ceil($comment_totalCount / $records_per_page);
                $where = array();
                $where['c.video_id'] = $comment['video_id'];
                $where['c.is_show'] = 1;
            } else {
                $where = array();
                $where['c.video_id'] = $video_id;
                $where['c.is_show'] = 1;
            }

            $list = $this->db->select("c.*,u1.nickname comment_nickname,u1.head_img comment_head_img,u2.nickname reply_nickname,u2.head_img reply_head_img")
                            ->from("video_comment c")
                            ->join("users_info u1", "u1.user_id = c.uid", "left")
                            ->join("users_info u2", "u2.user_id = c.repay_user_id", "left")
                            ->where($where)->order_by("c.id desc")->limit($records_per_page, $pageIndex * $records_per_page)->get()->result_array();

            $html = "";
            foreach ($list as $key => $val) {
                //获取引用的评论
                $uuid = encrypt_user_id($val['uid']);
                $is_self = $this->user_id == $val['uid'] ? 1 : 0;
                if ($val['rmd'] == 1) {
                    $rmd_str = '<img class="hot-comment" src="/static/weixin/img/hot-comment.png">';
                } else {
                    $rmd_str = '';
                }

                $lengther = mb_strlen($val['content'], "utf8");
                $show_more = $lengther > 50 ? "<a href='javascript:;' class='all col-red'>展开↓</a>" : "";

                if ($val['repay_user_id']) {
                    $reply_str = '<p class="text mt5 publicText">回复<a href="' . site_url("u/" . encrypt_user_id($val['repay_user_id'])) . '" class="col-red">' . $val['reply_nickname'] . '</a>：' . $val['content'] . '</p>' . $show_more;
                } else {
                    $reply_str = '<p class="text mt5 publicText">' . $val['content'] . '</p>' . $show_more;
                }
                $reply_btn_str = "<a href='javascript:;' class='publicText _reply' onclick=\"reply_comment_fn({comment_id:" . encrypt_comment_id($val['id']) . ",commenter_name:'$val[comment_nickname]',commenter_uid:$uuid});\">回复</a>";

                $val['comment_head_img'] = strstr($val['comment_head_img'], "http") ? $val['comment_head_img'] : $this->img_host . $val['comment_head_img'];
                $val['reply_head_img'] = strstr($val['reply_head_img'], "http") ? $val['reply_head_img'] : $this->img_host . $val['reply_head_img'];
                $html .= '<li class="f-cb ptb10" id="comment-' . encrypt_comment_id($val['id']) . '" data-cid="' . encrypt_comment_id($val['id']) . '" data->
                                <a href="' . site_url("u/" . encrypt_user_id($val['uid'])) . '" class="fl head-img"><img src="' . $val['comment_head_img'] . '"/></a>
                                <div class="pl45">
                                    <div class="comments-menu">
                                        <div class="menuToggle icon-menu iconfont fr">&#xe6a0;</div>
                                        <div class="menu-toggle">
                                            <b></b>
                                            ' . ($is_self ? '<a href="javascript:;" class="delete-jq" onclick="delete_video_comment_act({comment_id:' . encrypt_comment_id($val['id']) . ',obj:this});">删除</a>' : "") . '
                                            ' . $reply_btn_str . '
                                            <a href="javascript:;" class="publicReport _report" data-rel="http://www.tan66.com/video/' . $video['salt'] . '/comments/' . encrypt_comment_id($val['id']) . '.html">举报</a>
                                        </div>
                                    </div>
                                    <a href="' . site_url("u/" . encrypt_user_id($val['uid'])) . '" class="name">' . $val['comment_nickname'] . '<img src="/static/weixin/img/vip/vip1.png"/>' . $rmd_str . '</a>
                                    <p class="time mt5">' . $this->set_time_three($val['create_time']) . '</p>' . $reply_str . '
                                </div>
                     </li>';
            }
            echo $html;
            die;
        }
    }

    //删除视频评论
    function cancel_video_comment_act() {
        $this->is_login();
        if ($_POST) {
            $comment_id = isset($_POST['comment_id']) ? trim($_POST['comment_id']) : 0;
            $comment_id = decrypt_comment_id($comment_id);
            $comment = $this->db->select("*")->from("video_comment")->where(array("id" => $comment_id, "is_show" => 1))->order_by("id desc")->get()->row_array();
            if (!$comment) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "评论已删除或不存在";
                echo JSON($mess);
                exit;
            }

            if ($comment['uid'] != $this->user_id) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "非法操作";
                echo JSON($mess);
                exit;
            }

            $this->db->trans_begin();
            $query1 = $this->db->query("update tan_video_comment set is_show = 0 where id = " . $comment_id);
            $query2 = $this->db->query("update tan_video set commentnum = commentnum - 1 where id = " . $comment['video_id']);
            $video = $this->db->select("commentnum")->from("video")->where(array("id" => $comment['video_id']))->get()->row_array();
            if ($query1 && $query2) {
                $this->db->trans_commit();
                $mess['reqStatus'] = true;
                $mess['commentnum'] = $video['commentnum'];
                echo JSON($mess);
                exit;
            } else {
                $this->db->trans_rollback();
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作失败，请稍后重试";
                echo JSON($mess);
                exit;
            }
        }
    }

    //添加视频评论
    function comment_video_add() {
        $this->is_login();
        if ($_POST) {
            $video_id = isset($_REQUEST['vid']) ? trim($_REQUEST['vid']) : 0; //视频id
            $content = isset($_REQUEST['content']) ? trim($_REQUEST['content']) : ""; //评论内容
            $comment_id = isset($_REQUEST['comment_id']) ? trim($_REQUEST['comment_id']) : 0; //回复的评论id
            $comment_uid = isset($_REQUEST['comment_uid']) ? trim($_REQUEST['comment_uid']) : 0; //回复的评论者
            $card_index = isset($_REQUEST['card']) ? trim($_REQUEST['card']) : 0; //回复的卡通图片
            $comment_id = $comment_id ? decrypt_comment_id($comment_id) : 0;
            $comment_uid = $comment_uid ? decrypt_user_id($comment_uid) : 0;
            $video_id = decrypt_video_id($video_id);
            //获取视频
            $video = $this->db->select("id,authorid,commentnum,status,salt")->from("video")->where(array("id" => $video_id))->order_by("create_time desc")->get()->row_array();

            if (!$video) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "视频不存在或已被删除，无法评论哦";
                echo JSON($mess);
                exit;
            }
            //获取评论
            if ($comment_id) {
                $comment = $this->db->select("id,uid,content")->from("video_comment")->where(array("id" => $comment_id, "is_show" => 1))->order_by("create_time desc")->get()->row_array();
                if (!$comment) {
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "此评论不存在或已删除，无法回复哦";
                    echo JSON($mess);
                    exit;
                }
                if ($comment['uid'] != $comment_uid) {
                    $mess['reqStatus'] = false;
                    $mess['errorMsg'] = "非法操作" . $comment['uid'];
                    echo JSON($mess);
                    exit;
                }
            }

            if (strip_tags(trim($content)) == "") {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "回复内容不能为空！";
                echo JSON($mess);
                exit;
            }
            //如果评论的是视频作者本人
            $is_self = $video['authorid'] == $this->user_id;

            $data = array();
            $data["uid"] = $this->user_id;
            $data["video_id"] = $video['id'];
            $data["authorid"] = $video['authorid'];
            $data["content"] = strip_tags($content);
            $data["create_time"] = time();
            $data["month"] = date("Ym");
            $data["day"] = date("Ymd");
            $data["repay_user_id"] = $comment_uid ? $comment_uid : 0;
            $data["cid"] = $comment_id ? $comment_id : 0;
            $data["type"] = $comment_id ? 1 : 0;
            $data["card_index"] = $card_index;

            $this->db->trans_begin();
            $this->db->insert("video_comment", $data);
            $insert_id = $this->db->insert_id();
            $query2 = $this->db->query("update tan_video set commentnum = commentnum + 1 where id = " . $video['id']);

            if ($insert_id && $query2) {
                $this->db->trans_commit();
//                //更新个人动态
                $item = $this->db->select("c.*,u1.nickname comment_nickname,u1.head_img comment_head_img,u2.nickname reply_nickname,u2.head_img reply_head_img")
                                ->from("video_comment c")
                                ->join("users_info u1", "u1.user_id = c.uid", "left")
                                ->join("users_info u2", "u2.user_id = c.repay_user_id", "left")
                                ->where(array('c.id' => $insert_id))->order_by("id desc")->limit(1)->get()->row_array();

                $uuid = encrypt_user_id($item['uid']);

                $lengther = mb_strlen($item['content'], "utf8");
                $show_more = $lengther > 70 ? "<a href='javascript:;' class='all col-red'>展开↓</a>" : "";

                if ($item['repay_user_id']) {
                    $reply_str = '<p class="text mt5 publicText">回复<a href="' . site_url("u/" . encrypt_user_id($item['repay_user_id'])) . '" class="col-red">' . $item['reply_nickname'] . '</a>：' . $item['content'] . '</p>' . $show_more;
                } else {
                    $reply_str = '<p class="text mt5 publicText">' . $item['content'] . '</p>' . $show_more;
                }
                $reply_btn_str = "<a href='javascript:;' class='publicText _reply' onclick=\"reply_comment_fn({comment_id:" . encrypt_comment_id($item['id']) . ",commenter_name:'$item[comment_nickname]',commenter_uid:$uuid});\">回复</a>";

                $val['comment_head_img'] = strstr($val['comment_head_img'], "http") ? $val['comment_head_img'] : $this->img_host . $val['comment_head_img'];
                $val['reply_head_img'] = strstr($val['reply_head_img'], "http") ? $val['reply_head_img'] : $this->img_host . $val['reply_head_img'];
                $html = '<li class="f-cb ptb10" id="comment-' . encrypt_comment_id($item['id']) . '" data-cid="' . encrypt_comment_id($item['id']) . '" data->
                            <a href="' . site_url("u/" . encrypt_user_id($item['uid'])) . '" class="fl head-img"><img src="' . $item['comment_head_img'] . '"/></a>
                            <div class="pl45">
                                <div class="comments-menu">
                                    <div class="menuToggle icon-menu iconfont fr">&#xe6a0;</div>
                                    <div class="menu-toggle">
                                        <b></b>
                                        <a href="javascript:;" class="delete-jq" onclick="delete_video_comment_act({comment_id:' . encrypt_comment_id($item['id']) . ',obj:this});">删除</a>
                                        ' . $reply_btn_str . '
                                        <a href="javascript:;" class="publicReport _report" data-rel="http://www.tan66.com/video/' . $video['salt'] . '/comments/' . encrypt_comment_id($item['id']) . '.html">举报</a>
                                    </div>
                                </div>
                                <a href="' . site_url("u/" . encrypt_user_id($item['uid'])) . '" class="name">' . $item['comment_nickname'] . '<img src="../static/default/img/vip/vip1.png"/></a>
                                <p class="time mt5">' . $this->set_time_three($item['create_time']) . '</p>' . $reply_str . '
                            </div>
                        </li>';


                $mess['reqStatus'] = true;
                $mess['htmlData'] = $html;
                $mess['commentNum'] = $video['commentnum'] + 1;
                $mess['reqStatus'] = true;
                echo json_encode($mess, JSON_HEX_TAG);
                exit;
            } else {
                $this->db->trans_rollback();
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "操作失败，请稍后重试";
                echo JSON($mess);
                exit;
            }
        }
    }

    //意见反馈
    function ajax_add_feedback() {
        $this->is_login();
        if ($_POST) {
            $content = isset($_POST['content']) ? trim($_POST['content']) : "";
            if (!$content) {
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "内容不能为空哦";
                echo JSON($mess);
                exit;
            }
            $data = array(
                "feed_type" => 1,
                "feed_page" => "",
                "feed_content" => $content,
                "create_time" => time()
            );
            $this->db->insert("tan_feedback", $data);

            $mess['reqStatus'] = true;
            echo JSON($mess);
            exit;
        }
    }

    //添加毁灭地球活动信息
    function add_fraction() {
        $fraction = trim($_POST['fraction']); //总分
        $percentage = destructive_power($fraction);
        $data['create_time'] = time();
        $data['fraction'] = $fraction;
        $data['percentage'] = $percentage;
        $this->db->insert("activity_destroyearth", $data);
        $insert_id = $this->db->insert_id();
        if ($insert_id) {
            $mess['reqStatus'] = true;
            $mess['errorMsg'] = "恭喜您，填写成功！";
            $mess['percentage'] = $percentage;
            $mess['fraction'] = $fraction;
            $mess['link'] = "http://wx.tan66.com/destroyearth/res.html?id=" . $insert_id;
            $mess['title'] = "你毁灭地球的能力值为" . $fraction . "分，打败了全国" . $percentage . "的人，快来测试吧！";
            echo JSON($mess);
            exit;
        } else {
            $mess['reqStatus'] = false;
            $mess['errorMsg'] = "操作失败，请重试";
            echo JSON($mess);
            exit;
        }
    }

}
